/** * Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the * SHA-256 (256 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-256 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha256(byte[] key) { return hmacSha256(new SecretKeySpec(checkNotNull(key), "HmacSHA256")); }
/** * Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the * SHA-256 (256 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-256 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha256(byte[] key) { return hmacSha256(new SecretKeySpec(checkNotNull(key), "HmacSHA256")); }
/** * Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the * SHA-256 (256 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-256 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha256(byte[] key) { return hmacSha256(new SecretKeySpec(checkNotNull(key), "HmacSHA256")); }
@Inject public ProxyResource(@ForProxy HttpClient httpClient, JsonWebTokenHandler jwtHandler, ProxyConfig config) { this.httpClient = requireNonNull(httpClient, "httpClient is null"); this.jwtHandler = requireNonNull(jwtHandler, "jwtHandler is null"); this.remoteUri = requireNonNull(config.getUri(), "uri is null"); this.hmac = hmacSha256(loadSharedSecret(config.getSharedSecretFile())); }
@Description("Compute HMAC with SHA256") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice hmacSha256(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) { return wrappedBuffer(Hashing.hmacSha256(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-256 (256 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-256 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha256(byte[] key) { return hmacSha256(new SecretKeySpec(checkNotNull(key), "HmacSHA256")); }
/** * Returns a hash function implementing the Message Authentication Code (MAC) algorithm, using the * SHA-256 (256 hash bits) hash function and a {@link SecretKeySpec} created from the given byte * array and the SHA-256 algorithm. * * * @param key the key material of the secret key * @since 20.0 */ public static HashFunction hmacSha256(byte[] key) { return hmacSha256(new SecretKeySpec(checkNotNull(key), "HmacSHA256")); }
@Inject public ProxyResource(@ForProxy HttpClient httpClient, JsonWebTokenHandler jwtHandler, ProxyConfig config) { this.httpClient = requireNonNull(httpClient, "httpClient is null"); this.jwtHandler = requireNonNull(jwtHandler, "jwtHandler is null"); this.remoteUri = requireNonNull(config.getUri(), "uri is null"); this.hmac = hmacSha256(loadSharedSecret(config.getSharedSecretFile())); }
@Description("Compute HMAC with SHA256") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice hmacSha256(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) { return wrappedBuffer(Hashing.hmacSha256(key.getBytes()).hashBytes(slice.getBytes()).asBytes()); }
@Description("Compute HMAC with SHA256") @ScalarFunction @SqlType(StandardTypes.VARBINARY) public static Slice hmacSha256(@SqlType(StandardTypes.VARBINARY) Slice slice, @SqlType(StandardTypes.VARBINARY) Slice key) { return wrappedBuffer(Hashing.hmacSha256(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()); }