@Override public String toString() { return this.id + "_" + CodecUtil.b64(this.data); }
/** {@inheritDoc} */ @Override public String convert(@Nonnull final String source) { return "{sha1}" + CodecUtil.hex(HashUtil.sha1(source.getBytes())); } }
/** * Decodes a base64-encoded string into raw bytes. * * @param encoded Base64-encoded character data. * * @return Base64-decoded bytes. * * @throws EncodingException on decoding errors. */ public static byte[] b64(final CharSequence encoded) throws EncodingException { return decode(new Base64Decoder(), encoded); }
/** * Gets an encoded string of the concatenation of digest output and salt. * * @param toEnd True to append salt to end of hash, false to prefix hash with salt. * @param encoder Encodes concatenated bytes to a string. * * @return Salt concatenated to hash encoded as a string. */ public String concatenateSalt(final boolean toEnd, final Encoder encoder) { return CodecUtil.encode(encoder, concatenateSalt(toEnd)); }
/** * Encodes raw bytes to the equivalent hexadecimal encoded string. * * @param raw Raw bytes to encode. * * @return Hexadecimal encoded string. * * @throws EncodingException on encoding errors. */ public static String hex(final byte[] raw) throws EncodingException { return encode(new HexEncoder(), raw); }
@Override public String apply(@Nonnull final String input) { return CodecUtil.hex(HashUtil.sha1(input.getBytes())); }
/** {@inheritDoc} */ @Override @Nullable public String apply(@Nonnull final String input) { if (input == null) { return null; } return CodecUtil.b64(HashUtil.sha256(input)); } }
/** * Encodes bytes into base 64-encoded string. * * @param raw Raw bytes to encode. * * @return Base64-encoded string. * * @throws EncodingException on encoding errors. */ public static String b64(final byte[] raw) throws EncodingException { return encode(new Base64Encoder(), raw); }
/** * Decodes a base32-encoded string into raw bytes. * * @param encoded Base32-encoded character data. * * @return Base64-decoded bytes. * * @throws EncodingException on decoding errors. */ public static byte[] b32(final CharSequence encoded) throws EncodingException { return decode(new Base32Decoder(), encoded); }
/** {@inheritDoc} */ @Override public String convert(@Nonnull final String source) { return "{md5}" + CodecUtil.hex(HashUtil.hash(new MD5Digest(), source.getBytes())); } }
/** {@inheritDoc} */ @Override @Nullable public String apply(@Nonnull final String input) { if (input == null) { return null; } return CodecUtil.b64(HashUtil.sha256(input)); } }
/** * Encodes bytes into base 32-encoded string. * * @param raw Raw bytes to encode. * * @return Base32-encoded string. * * @throws EncodingException on encoding errors. */ public static String b32(final byte[] raw) throws EncodingException { return encode(new Base32Encoder(), raw); }
/** * Decodes a hexadecimal encoded string to raw bytes. * * @param encoded Hex encoded character data. * * @return Raw bytes of hex string. * * @throws EncodingException on decoding errors. */ public static byte[] hex(final CharSequence encoded) throws EncodingException { return decode(new HexDecoder(), encoded); }
/** * Creates a memcached key from one or more parts. * * @param parts Key parts (i.e. namespace, local name) * * @return Key comprised of 250 characters or less. */ private String memcachedKey(final String ... parts) { final String key; if (parts.length > 0) { final StringBuilder sb = new StringBuilder(); int i = 0; for (String part : parts) { if (i++ > 0) { sb.append(':'); } sb.append(part); } key = sb.toString(); } else { key = parts[0]; } if (key.length() > MAX_KEY_LENGTH) { return CodecUtil.hex(HashUtil.sha512(key)); } return key; }
public static ClientFlowExecutionKey parse(final String key) throws BadlyFormattedFlowExecutionKeyException { final String[] tokens = key.split("_"); if (tokens.length != 2) { throw new BadlyFormattedFlowExecutionKeyException(key, KEY_FORMAT); } final UUID uuid; try { uuid = UUID.fromString(tokens[0]); } catch (Exception e) { throw new BadlyFormattedFlowExecutionKeyException(key, KEY_FORMAT); } final byte[] decoded; try { decoded = CodecUtil.b64(tokens[1]); } catch (Exception e) { throw new BadlyFormattedFlowExecutionKeyException(key, KEY_FORMAT); } return new ClientFlowExecutionKey(uuid, decoded); }
/** * Encodes bytes into base32-encoded string. * * @param raw Raw bytes to encode. * @param lineLength Length of each base32-encoded line in output. * * @return Base32-encoded string. * * @throws EncodingException on encoding errors. */ public static String b32(final byte[] raw, final int lineLength) throws EncodingException { return encode(new Base32Encoder(lineLength), raw); }
/** * Compares a known hash value with the hash of the given data. * * @param hash Known encoded hash value. If the length of the hash bytes after decoding is greater than the length * of the digest output, anything beyond the digest length is considered salt data that is hashed * <strong>after</strong> the input data. * @param data Data to hash. * * @return True if the hashed data matches the given hash, false otherwise. * * @throws CryptoException on hash computation errors. * @throws EncodingException on encoding errors. * @throws StreamException on stream IO errors. */ @Override public boolean compare(final String hash, final Object... data) throws CryptoException, EncodingException, StreamException { return compareInternal(CodecUtil.decode(codecSpec.newInstance().getDecoder(), hash), data); } }
@Override protected byte[] decryptKey(final byte[] encrypted, final char[] password) { final String pem = new String(encrypted, ByteUtil.ASCII_CHARSET); final int start = pem.indexOf(PemUtil.DEK_INFO); final int eol = pem.indexOf('\n', start); final String[] dekInfo = pem.substring(start + 10, eol).split(","); final String alg = dekInfo[0]; final byte[] iv = CodecUtil.hex(dekInfo[1]); final byte[] bytes = PemUtil.decode(encrypted); return new OpenSSLEncryptionScheme(OpenSSLAlgorithm.fromAlgorithmId(alg), iv, password).decrypt(bytes); }
byteArrayOutputStream.close(); return CodecUtil.b64(HashUtil.sha256(byteArrayOutputStream.toByteArray()));
/** * Encodes bytes into base64-encoded string. * * @param raw Raw bytes to encode. * @param lineLength Length of each base64-encoded line in output. * * @return Base64-encoded string. * * @throws EncodingException on encoding errors. */ public static String b64(final byte[] raw, final int lineLength) throws EncodingException { return encode(new Base64Encoder(lineLength), raw); }