/** * Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the * SHA-1 (160 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-1 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha1(byte[] key) { return hmacSha1(new SecretKeySpec(checkNotNull(key), "HmacSHA1")); }
/** * Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the * SHA-1 (160 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-1 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha1(byte[] key) { return hmacSha1(new SecretKeySpec(checkNotNull(key), "HmacSHA1")); }
/** * Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the * SHA-1 (160 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-1 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha1(byte[] key) { return hmacSha1(new SecretKeySpec(checkNotNull(key), "HmacSHA1")); }
private static void checkSha1(String expected, byte[] key, byte[] data) { checkHmac(expected, Hashing.hmacSha1(key), data); }
public void testMultipleUpdates() throws Exception { Mac mac = Mac.getInstance("HmacSHA1"); mac.init(SHA1_KEY); mac.update("hello".getBytes(UTF_8)); mac.update("world".getBytes(UTF_8)); assertEquals( HashCode.fromBytes(mac.doFinal()), Hashing.hmacSha1(SHA1_KEY) .newHasher() .putString("hello", UTF_8) .putString("world", UTF_8) .hash()); }
public void testMultipleUpdatesDoFinal() throws Exception { Mac mac = Mac.getInstance("HmacSHA1"); mac.init(SHA1_KEY); mac.update("hello".getBytes(UTF_8)); mac.update("world".getBytes(UTF_8)); assertEquals( HashCode.fromBytes(mac.doFinal("!!!".getBytes(UTF_8))), Hashing.hmacSha1(SHA1_KEY) .newHasher() .putString("hello", UTF_8) .putString("world", UTF_8) .putString("!!!", UTF_8) .hash()); }
@Description("Compute HMAC with SHA1") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice hmacSha1(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) { return wrappedBuffer(Hashing.hmacSha1(key.getBytes()).hashBytes(slice.getBytes()).asBytes()); }
public void testToString() { byte[] keyData = "secret key".getBytes(UTF_8); assertEquals( "Hashing.hmacMd5(Key[algorithm=HmacMD5, format=RAW])", Hashing.hmacMd5(MD5_KEY).toString()); assertEquals( "Hashing.hmacMd5(Key[algorithm=HmacMD5, format=RAW])", Hashing.hmacMd5(keyData).toString()); assertEquals( "Hashing.hmacSha1(Key[algorithm=HmacSHA1, format=RAW])", Hashing.hmacSha1(SHA1_KEY).toString()); assertEquals( "Hashing.hmacSha1(Key[algorithm=HmacSHA1, format=RAW])", Hashing.hmacSha1(keyData).toString()); assertEquals( "Hashing.hmacSha256(Key[algorithm=HmacSHA256, format=RAW])", Hashing.hmacSha256(SHA256_KEY).toString()); assertEquals( "Hashing.hmacSha256(Key[algorithm=HmacSHA256, format=RAW])", Hashing.hmacSha256(keyData).toString()); assertEquals( "Hashing.hmacSha512(Key[algorithm=HmacSHA512, format=RAW])", Hashing.hmacSha512(SHA512_KEY).toString()); assertEquals( "Hashing.hmacSha512(Key[algorithm=HmacSHA512, format=RAW])", Hashing.hmacSha512(keyData).toString()); }
/** * Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the * SHA-1 (160 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-1 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha1(byte[] key) { return hmacSha1(new SecretKeySpec(checkNotNull(key), "HmacSHA1")); }
/** * Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the * SHA-1 (160 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-1 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha1(byte[] key) { return hmacSha1(new SecretKeySpec(checkNotNull(key), "HmacSHA1")); }
private static void checkSha1(String expected, byte[] key, byte[] data) { checkHmac(expected, Hashing.hmacSha1(key), data); }
public void testMultipleUpdates() throws Exception { Mac mac = Mac.getInstance("HmacSHA1"); mac.init(SHA1_KEY); mac.update("hello".getBytes(UTF_8)); mac.update("world".getBytes(UTF_8)); assertEquals( HashCode.fromBytes(mac.doFinal()), Hashing.hmacSha1(SHA1_KEY).newHasher() .putString("hello", UTF_8) .putString("world", UTF_8) .hash()); }
@Description("Compute HMAC with SHA1") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice hmacSha1(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) { return wrappedBuffer(Hashing.hmacSha1(key.getBytes()).hashBytes(slice.getBytes()).asBytes()); }
public void testMultipleUpdatesDoFinal() throws Exception { Mac mac = Mac.getInstance("HmacSHA1"); mac.init(SHA1_KEY); mac.update("hello".getBytes(UTF_8)); mac.update("world".getBytes(UTF_8)); assertEquals( HashCode.fromBytes(mac.doFinal("!!!".getBytes(UTF_8))), Hashing.hmacSha1(SHA1_KEY).newHasher() .putString("hello", UTF_8) .putString("world", UTF_8) .putString("!!!", UTF_8) .hash()); }
@Description("Compute HMAC with SHA1") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice hmacSha1(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) { return wrappedBuffer(Hashing.hmacSha1(key.getBytes()).hashBytes(slice.getBytes()).asBytes()); }
public void testToString() { byte[] keyData = "secret key".getBytes(UTF_8); assertEquals( "Hashing.hmacMd5(Key[algorithm=HmacMD5, format=RAW])", Hashing.hmacMd5(MD5_KEY).toString()); assertEquals( "Hashing.hmacMd5(Key[algorithm=HmacMD5, format=RAW])", Hashing.hmacMd5(keyData).toString()); assertEquals( "Hashing.hmacSha1(Key[algorithm=HmacSHA1, format=RAW])", Hashing.hmacSha1(SHA1_KEY).toString()); assertEquals( "Hashing.hmacSha1(Key[algorithm=HmacSHA1, format=RAW])", Hashing.hmacSha1(keyData).toString()); assertEquals( "Hashing.hmacSha256(Key[algorithm=HmacSHA256, format=RAW])", Hashing.hmacSha256(SHA256_KEY).toString()); assertEquals( "Hashing.hmacSha256(Key[algorithm=HmacSHA256, format=RAW])", Hashing.hmacSha256(keyData).toString()); assertEquals( "Hashing.hmacSha512(Key[algorithm=HmacSHA512, format=RAW])", Hashing.hmacSha512(SHA512_KEY).toString()); assertEquals( "Hashing.hmacSha512(Key[algorithm=HmacSHA512, format=RAW])", Hashing.hmacSha512(keyData).toString()); }