@Test public void testHmacSha1UpdateWithInpustream() throws IOException { final Mac mac = HmacUtils.getHmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES); HmacUtils.updateHmac(mac, new ByteArrayInputStream(HmacAlgorithmsTest.STANDARD_PHRASE_BYTES)); assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal())); HmacUtils.updateHmac(mac, new ByteArrayInputStream("".getBytes())); assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal())); }
@Test public void testHmacSha1UpdateWithByteArray() throws IOException { final Mac mac = HmacUtils.getHmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES); HmacUtils.updateHmac(mac, HmacAlgorithmsTest.STANDARD_PHRASE_BYTES); assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal())); HmacUtils.updateHmac(mac, "".getBytes()); assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal())); }
@Test public void testHmacSha1UpdateWithString() throws IOException { final Mac mac = HmacUtils.getHmacSha1(HmacAlgorithmsTest.STANDARD_KEY_BYTES); HmacUtils.updateHmac(mac, HmacAlgorithmsTest.STANDARD_PHRASE_STRING); assertEquals(HmacAlgorithmsTest.STANDARD_SHA1_RESULT_STRING, Hex.encodeHexString(mac.doFinal())); HmacUtils.updateHmac(mac, ""); assertEquals("f42bb0eeb018ebbd4597ae7213711ec60760843f", Hex.encodeHexString(mac.doFinal())); }
@Test public void testInitializedMac() throws IOException { final Mac md5Mac = HmacUtils.getInitializedMac(HmacAlgorithms.HMAC_MD5, HmacAlgorithmsTest.STANDARD_KEY_BYTES); final Mac md5Mac2 = HmacUtils.getInitializedMac("HmacMD5", HmacAlgorithmsTest.STANDARD_KEY_BYTES); Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES, HmacUtils.updateHmac(md5Mac, HmacAlgorithmsTest.STANDARD_PHRASE_STRING) .doFinal()); Assert.assertArrayEquals(HmacAlgorithmsTest.STANDARD_MD5_RESULT_BYTES, HmacUtils.updateHmac(md5Mac2, HmacAlgorithmsTest.STANDARD_PHRASE_STRING) .doFinal()); }
@Test public void testInitializedMac() throws IOException { final Mac mac = HmacUtils.getInitializedMac(hmacAlgorithm, STANDARD_KEY_BYTES); final Mac mac2 = HmacUtils.getInitializedMac(hmacAlgorithm.getName(), STANDARD_KEY_BYTES); Assert.assertArrayEquals(standardResultBytes, HmacUtils.updateHmac(mac, STANDARD_PHRASE_STRING).doFinal()); Assert.assertArrayEquals(standardResultBytes, HmacUtils.updateHmac(mac2, STANDARD_PHRASE_STRING).doFinal()); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA1 MAC for the given key and value * @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 byte[] hmacSha1(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha1(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA512 MAC for the given key and value * @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 byte[] hmacSha512(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha512(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacMD5 MAC for the given key and value * @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 byte[] hmacMd5(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacMd5(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA384 MAC for the given key and value * @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 byte[] hmacSha384(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha384(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA1 MAC for the given key and value * @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 byte[] hmacSha1(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha1(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA512 MAC for the given key and value * @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 byte[] hmacSha512(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha512(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA512 MAC for the given key and value * @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 byte[] hmacSha512(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha512(key), valueToDigest).doFinal(); }
/** * Returns a HmacSHA256 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA256 MAC for the given key and value * @throws IOException * If an I/O error occurs. s * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. */ public static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha256(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacMD5 MAC for the given key and value * @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 byte[] hmacMd5(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacMd5(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA1 MAC for the given key and value * @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 byte[] hmacSha1(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha1(key), valueToDigest).doFinal(); }
/** * Returns a HmacSHA256 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA256 MAC for the given key and value * @throws IOException * If an I/O error occurs. s * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. */ public static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha256(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA384 MAC for the given key and value * @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 byte[] hmacSha384(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha384(key), valueToDigest).doFinal(); }
/** * Returns a HmacSHA256 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA256 MAC for the given key and value * @throws IOException * If an I/O error occurs. s * @throws IllegalArgumentException * when a {@link NoSuchAlgorithmException} is caught or key is null or key is invalid. */ public static byte[] hmacSha256(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha256(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacMD5 MAC for the given key and value * @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 byte[] hmacMd5(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacMd5(key), valueToDigest).doFinal(); }
/** * 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 * <p> * The InputStream must not be null and will not be closed * </p> * @return HmacSHA384 MAC for the given key and value * @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 byte[] hmacSha384(final byte[] key, final InputStream valueToDigest) throws IOException { return updateHmac(getHmacSha384(key), valueToDigest).doFinal(); }