/** * 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 HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) 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 as hex string (lowercase) * @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, String).hmacHex(String)} */ @Deprecated public static String hmacSha512Hex(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_512, key).hmacHex(valueToDigest); }
/** * Returns a HmacMD5 Message Authentication Code (MAC) as a hex string (lowercase) 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 as a hex string (lowercase) * @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).hmacHex(String)} */ @Deprecated public static String hmacMd5Hex(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_MD5, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA1 Message Authentication Code (MAC) as hex string (lowercase) 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 as hex string (lowercase) * @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[]).hmacHex(byte[])} */ @Deprecated public static String hmacSha1Hex(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_1, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA384 Message Authentication Code (MAC) as hex string (lowercase) 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 as hex string (lowercase) * @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, String).hmacHex(String)} */ @Deprecated public static String hmacSha384Hex(final String key, final String valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_384, key).hmacHex(valueToDigest); }
/** * Returns a HmacSHA512 Message Authentication Code (MAC) as hex string (lowercase) 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 as hex string (lowercase) * @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[]).hmacHex(byte[])} */ @Deprecated public static String hmacSha512Hex(final byte[] key, final byte[] valueToDigest) { return new HmacUtils(HmacAlgorithms.HMAC_SHA_512, key).hmacHex(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 testMacHexInputStream() throws IOException { Assert.assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(new ByteArrayInputStream(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 testMacHexByteArray() throws IOException { Assert.assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(STANDARD_PHRASE_BYTES)); }
@Test public void testMacHexString() throws IOException { Assert.assertEquals(standardResultString, new HmacUtils(hmacAlgorithm, STANDARD_KEY_BYTES).hmacHex(STANDARD_PHRASE_STRING)); }
@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)); }