/** * Given a piece of text and a message signature encoded in base64, returns an ECKey * containing the public key that was used to sign it. This can then be compared to the expected public key to * determine if the signature was correct. * * @param messageHash a piece of human readable text that was signed * @param signatureBase64 The Ethereum-format message signature in base64 * * @return - * @throws SignatureException If the public key could not be recovered or if there was a signature format error. */ public static byte[] signatureToKeyBytes(byte[] messageHash, String signatureBase64) throws SignatureException { byte[] signatureEncoded; try { signatureEncoded = Base64.decode(signatureBase64); } catch (RuntimeException e) { // This is what you get back from Bouncy Castle if base64 doesn't decode :( throw new SignatureException("Could not decode base64", e); } // Parse the signature bytes into r/s and the selector value. if (signatureEncoded.length < 65) throw new SignatureException("Signature truncated, expected 65 bytes and got " + signatureEncoded.length); return signatureToKeyBytes( messageHash, ECDSASignature.fromComponents( Arrays.copyOfRange(signatureEncoded, 1, 33), Arrays.copyOfRange(signatureEncoded, 33, 65), (byte) (signatureEncoded[0] & 0xFF))); }
/** * <p>base64Decode.</p> * * @param string a {@link java.lang.String} object. * @return an array of byte. */ public static byte[] base64Decode(String string) { return Base64.decode(string); }
public static byte[] Base64ToBytes(String data) { return Base64.decode(data); }
@Override public byte[] read(String value) throws Exception { return Base64.decode(value.getBytes()); }
@Override public UUID read(String value) throws Exception { if(value == null) { return null; } return ByteUtils.bytesToUUID(Base64.decode(value.getBytes())); }
private boolean isValidToken(String token) { try { String tokenParamsJsonB64 = token.split("\\.")[1] + "="; String tokenParamsJson = new String(Base64.decode(tokenParamsJsonB64.getBytes("utf-8"))); JsonFactory factory = new JsonFactory(); ObjectMapper mapper = new ObjectMapper(factory); JsonNode rootNode = mapper.readTree(tokenParamsJson); long expDate = rootNode.get("exp").asLong() * 1000; long now = System.currentTimeMillis(); return now < expDate; } catch (Exception e) { return false; } }
/** {@inheritDoc} */ @Override public byte[] base64Decode(String string) { return Base64.decode(StringUtils.removeWhitespace(string)); }
@Override public KeyFileBytes readKeyFile(byte[] keyFile) { byte[] protectedBuffer = keyFile; int length = keyFile.length; if (length == 64) { protectedBuffer = Base64.decode(keyFile); } return new KeyFileBytes(true, protectedBuffer); }
/** {@inheritDoc} */ @Override public byte[] base64Decode(String string) { return Base64.decode(StringUtils.removeWhitespace(string)); }
private byte[] readIvFromFileOrGenerateNew() { final String encoded = null;// = this.preferences.getString(IV, null); if (encoded == null) { return generateAndSaveIv(); } return Base64.decode(encoded); }
static String decrypt(long key, String fullMessage) throws DataFormatException { byte[] bytes = decryptBytes(key, Base64.decode(fullMessage)); return new String(bytes); }
static String decrypt(long key, String fullMessage) throws DataFormatException { byte[] bytes = decryptBytes(key, Base64.decode(fullMessage)); return new String(bytes); }
public String decrypt(final String cryptedText, final String password) { if (this.cipher == null) { initWithPassword(password); } try { cipher.init(Cipher.DECRYPT_MODE, key, spec); final byte[] bytes = Base64.decode(cryptedText); final byte[] decrypted = cipher.doFinal(bytes); return new String(decrypted, "UTF-8"); } catch (InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | UnsupportedEncodingException e) { throw new RuntimeException(e); } }
public static String decode(String input) { return Strings.fromByteArray(org.spongycastle.util.encoders.Base64.decode(input)); }
@Override public String decrypt(String protectedString) { if (protectedString == null) { throw new IllegalArgumentException("ProtectedString must not be null"); } byte[] protectedBuffer = Base64.decode(protectedString.getBytes()); byte[] plainText = new byte[protectedBuffer.length]; try { salsa20Engine.processBytes(protectedBuffer, 0, protectedBuffer.length, plainText, 0); return new String(plainText, ENCODING); } catch (UnsupportedEncodingException e) { throw new UnsupportedOperationException(MSG_UNKNOWN_UTF8_ENCODING, e); } }
private byte[] getBytesFromKeyFile(KeyFile keyFile) { try { return Base64.decode(keyFile.getKey().getData().getBytes(UTF_8)); } catch (UnsupportedEncodingException e) { throw new UnsupportedOperationException(MSG_UTF8_NOT_SUPPORTED, e); } } }
public static byte[] signatureToKeyBytes(byte[] messageHash, String signatureBase64) throws SignatureException { byte[] signatureEncoded; try { signatureEncoded = Base64.decode(signatureBase64); } catch (RuntimeException e) { // This is what you getData back from Bouncy Castle if base64 doesn't // decode :( throw new SignatureException("Could not decode base64", e); } // Parse the signature bytes into r/s and the selector value. if (signatureEncoded.length < 65) { throw new SignatureException("Signature truncated, expected 65 " + "bytes and got " + signatureEncoded.length); } return signatureToKeyBytes( messageHash, ECDSASignature.fromComponents( Arrays.copyOfRange(signatureEncoded, 1, 33), Arrays.copyOfRange(signatureEncoded, 33, 65), (byte) (signatureEncoded[0] & 0xFF))); }
public Binder extractParams(BasicHTTPService.Request request) { Binder rp = request.getParams(); String sparams = rp.getString("requestData64", null); if (sparams != null) { byte [] x = Base64.decode(sparams); return Boss.unpack(x); } else { BasicHTTPService.FileUpload rd = (BasicHTTPService.FileUpload) rp.get("requestData"); if (rd != null) { byte[] data = rd.getBytes(); return Boss.unpack(data); } } return Binder.EMPTY; }
/** * Get metadata entry */ private String getMetadataEntry(String address, boolean isEncrypted) throws MetadataException, IOException, InvalidCipherTextException { Call<MetadataResponse> response = getApiInstance().getMetadata(address); Response<MetadataResponse> exe = response.execute(); if (exe.isSuccessful()) { if (isEncrypted) { return AESUtil.decryptWithKey(encryptionKey, exe.body().getPayload()); } else { return new String(Base64.decode(exe.body().getPayload())); } } else { if (exe.code() == 404) { return null; } else { throw new MetadataException(exe.code() + " " + exe.message()); } } }
public void fetchMagic() throws IOException, MetadataException { Call<MetadataResponse> response = getApiInstance().getMetadata(address); Response<MetadataResponse> exe = response.execute(); if (exe.isSuccessful()) { MetadataResponse body = exe.body(); byte[] encryptedPayloadBytes = Base64.decode(exe.body().getPayload().getBytes("utf-8")); if (body.getPrevMagicHash() != null) { byte[] prevMagicBytes = Hex.decode(body.getPrevMagicHash()); magicHash = MetadataUtil.magic(encryptedPayloadBytes, prevMagicBytes); } else { magicHash = MetadataUtil.magic(encryptedPayloadBytes, null); } } else { if (exe.code() == 404) { magicHash = null; } else { throw new MetadataException(exe.code() + " " + exe.message()); } } }