/** * 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); }
/** * 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 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); }
/** * 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); }
/** * 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); }
/** * Encodes raw bytes to the equivalent hexadecimal encoded string with optional delimiting of output. * * @param raw Raw bytes to encode. * @param delimit True to delimit every two characters (i.e. every byte) of output with ':' character, false * otherwise. * * @return Hexadecimal encoded string. * * @throws EncodingException on encoding errors. */ public static String hex(final byte[] raw, final boolean delimit) throws EncodingException { return encode(new HexEncoder(delimit), raw); }
/** * 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); }
/** * Hashes the given data. If {@link #isSalted()} is true then the last parameter MUST be a byte array containing the * salt. The salt value will be appended to the encoded hash that is returned. * * @param data Data to hash. * * @return Encoded digest output, including a salt if provided. * * @throws CryptoException on hash computation errors. * @throws EncodingException on encoding errors. * @throws StreamException on stream IO errors. */ @Override public String hash(final Object... data) throws CryptoException, EncodingException, StreamException { if (salted) { if (data.length < 2 || !(data[data.length - 1] instanceof byte[])) { throw new IllegalArgumentException("Last parameter must be a salt of type byte[]"); } final byte[] hashSalt = (byte[]) data[data.length - 1]; return CodecUtil.encode(codecSpec.newInstance().getEncoder(), Arrays.concatenate(hashInternal(data), hashSalt)); } return CodecUtil.encode(codecSpec.newInstance().getEncoder(), hashInternal(data)); }