/** * Returns the digest for the file. * * @param valueToDigest the file to use * @return the digest as a hex String * @throws IOException * If an I/O error occurs. * @since 1.11 */ public String hmacHex(final File valueToDigest) throws IOException { return Hex.encodeHexString(hmac(valueToDigest)); }
/** * Returns the digest for the input data. * * @param valueToDigest the input to use, treated as UTF-8 * @return the digest as a hex String * @since 1.11 */ public String hmacHex(final String valueToDigest) { return Hex.encodeHexString(hmac(valueToDigest)); }
/** * Returns the digest for the input data. * * @param valueToDigest the input to use * @return the digest as a hex String * @since 1.11 */ public String hmacHex(final ByteBuffer valueToDigest) { return Hex.encodeHexString(hmac(valueToDigest)); }
/** * Returns the digest for the input data. * * @param valueToDigest the input to use * @return the digest as a hex String * @since 1.11 */ public String hmacHex(final byte[] valueToDigest) { return Hex.encodeHexString(hmac(valueToDigest)); }
/** * Returns the digest for the stream. * * @param valueToDigest * the data to use * <p> * The InputStream must not be null and will not be closed * </p> * @return the digest as a hex String * @throws IOException * If an I/O error occurs. * @since 1.11 */ public String hmacHex(final InputStream valueToDigest) throws IOException { return Hex.encodeHexString(hmac(valueToDigest)); }
/** * Returns a HmacSHA512 Message Authentication Code (MAC) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA512 MAC for the given key and value * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_512, byte[]).hmac(byte[])} */ @Deprecated public static byte[] hmacSha512(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_512, key).hmac(valueToDigest); }
/** * Returns a HmacMD5 Message Authentication Code (MAC) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacMD5 MAC for the given key and value * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_MD5, byte[]).hmac(byte[])} */ @Deprecated public static byte[] hmacMd5(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_MD5, key).hmac(valueToDigest); }
/** * Returns a HmacMD5 Message Authentication Code (MAC) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacMD5 MAC for the given key and value * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_MD5, String).hmac(String)} */ @Deprecated public static byte[] hmacMd5(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_MD5, key).hmac(valueToDigest); }
/** * Returns a HmacSHA384 Message Authentication Code (MAC) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA384 MAC for the given key and value * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_384, byte[]).hmac(byte[])} */ @Deprecated public static byte[] hmacSha384(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_384, key).hmac(valueToDigest); }
/** * Returns a HmacSHA1 Message Authentication Code (MAC) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA1 MAC for the given key and value * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_1, String).hmac(String)} */ @Deprecated public static byte[] hmacSha1(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_1, key).hmac(valueToDigest); }
/** * Returns a HmacSHA1 Message Authentication Code (MAC) for the given key and value. * * @param key * They key for the keyed digest (must not be null) * @param valueToDigest * The value (data) which should to digest (maybe empty or null) * @return HmacSHA1 MAC for the given key and value * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. * @deprecated (1.11) Use {@code new HmacUtils(HmacAlgorithms.HMAC_SHA_1, byte[]).hmac(byte[])} */ @Deprecated public static byte[] hmacSha1(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_1, key).hmac(valueToDigest); }
@Test(expected = IllegalArgumentException.class) public void testHmacHexFailInputStream() throws IOException { new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(new ByteArrayInputStream(STANDARD_PHRASE_BYTES)); }
@Test(expected = IllegalArgumentException.class) public void testHmacFailInputStream() throws IOException { new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(new ByteArrayInputStream(STANDARD_PHRASE_BYTES)); }
@Test(expected = IllegalArgumentException.class) public void testHmacHexFailString() throws IOException { new HmacUtils(hmacAlgorithm, (String) null).hmac(STANDARD_PHRASE_STRING); }
@Test(expected = IllegalArgumentException.class) public void testHmacFailByteArray() throws IOException { new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(STANDARD_PHRASE_BYTES); }
@Test(expected = IllegalArgumentException.class) public void testHmacFailString() throws IOException { new HmacUtils(hmacAlgorithm, (String) null).hmac(STANDARD_PHRASE_STRING); }
@Test(expected = IllegalArgumentException.class) public void testHmacHexFailByteArray() throws IOException { new HmacUtils(hmacAlgorithm, (byte[]) null).hmac(STANDARD_PHRASE_BYTES); }
@Test public void testMacInputStream() throws IOException { Assert.assertArrayEquals(standardResultBytes, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmac(new ByteArrayInputStream(STANDARD_PHRASE_BYTES))); }
@Test public void testMacString() throws IOException { Assert.assertArrayEquals(standardResultBytes, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmac(STANDARD_PHRASE_STRING)); }
@Test public void testMacByteArary() throws IOException { Assert.assertArrayEquals(standardResultBytes, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmac(STANDARD_PHRASE_BYTES)); }