@Test(expected = IllegalArgumentException.class) public void testMd5HMacFail() throws IOException { HmacUtils.hmacMd5((byte[]) null, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES); }
@Test public void testMd5HMac() throws IOException { Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES, HmacUtils.hmacMd5(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)); Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES, HmacUtils.hmacMd5(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES))); Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES, HmacUtils.hmacMd5(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING)); Assert.assertEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_STRING, HmacUtils.hmacMd5Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)); Assert.assertEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_STRING, HmacUtils.hmacMd5Hex(HmacAlgorithmsTest.STANDARD_KEY_BYTES, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES))); Assert.assertEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_STRING, HmacUtils.hmacMd5Hex(HmacAlgorithmsTest.STANDARD_KEY_STRING, HmacAlgorithmsTest.STANDARD_PHRASE_STRING)); }
/** * 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. */ public static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest) { return Hex.encodeHexString(hmacMd5(key, 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. */ public static String hmacMd5Hex(final String key, final String valueToDigest) { return Hex.encodeHexString(hmacMd5(key, 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. */ public static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest) { return Hex.encodeHexString(hmacMd5(key, 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. */ public static String hmacMd5Hex(final String key, final String valueToDigest) { return Hex.encodeHexString(hmacMd5(key, 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. */ public static String hmacMd5Hex(final byte[] key, final byte[] valueToDigest) { return Hex.encodeHexString(hmacMd5(key, 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. */ public static String hmacMd5Hex(final String key, final String valueToDigest) { return Hex.encodeHexString(hmacMd5(key, 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacMD5 MAC for the given key and value as a hex string (lowercase) * @throws IOException * If an I/O error occurs. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. */ public static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest) throws IOException { return Hex.encodeHexString(hmacMd5(key, 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacMD5 MAC for the given key and value as a hex string (lowercase) * @throws IOException * If an I/O error occurs. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. */ public static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest) throws IOException { return Hex.encodeHexString(hmacMd5(key, 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacMD5 MAC for the given key and value as a hex string (lowercase) * @throws IOException * If an I/O error occurs. * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. */ public static String hmacMd5Hex(final byte[] key, final InputStream valueToDigest) throws IOException { return Hex.encodeHexString(hmacMd5(key, 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. */ public static byte[] hmacMd5(final String key, final String valueToDigest) { return hmacMd5(StringUtils.getBytesUtf8(key), StringUtils.getBytesUtf8(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. */ public static byte[] hmacMd5(final String key, final String valueToDigest) { return hmacMd5(StringUtils.getBytesUtf8(key), StringUtils.getBytesUtf8(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. */ public static byte[] hmacMd5(final String key, final String valueToDigest) { return hmacMd5(StringUtils.getBytesUtf8(key), StringUtils.getBytesUtf8(valueToDigest)); }