Add varargs variant to HmacUtil
This commit is contained in:
parent
2adf1e5017
commit
4e5dd914dd
|
@ -27,16 +27,28 @@ public final class HmacUtils {
|
|||
}
|
||||
});
|
||||
|
||||
public static byte[] hmac256(final byte[] key, final byte[] input) {
|
||||
private static Mac initializedThreadLocalMac(final byte[] key) {
|
||||
try {
|
||||
final Mac mac = THREAD_LOCAL_HMAC_SHA_256.get();
|
||||
mac.init(new SecretKeySpec(key, HMAC_SHA_256));
|
||||
return mac.doFinal(input);
|
||||
return mac;
|
||||
} catch (final InvalidKeyException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] hmac256(final byte[] key, final byte[] input) {
|
||||
return initializedThreadLocalMac(key).doFinal(input);
|
||||
}
|
||||
|
||||
public static byte[] hmac256(final byte[] key, final byte[]... inputs) {
|
||||
final Mac mac = initializedThreadLocalMac(key);
|
||||
for (byte[] input : inputs) {
|
||||
mac.update(input);
|
||||
}
|
||||
return mac.doFinal();
|
||||
}
|
||||
|
||||
public static byte[] hmac256(final byte[] key, final String input) {
|
||||
return hmac256(key, input.getBytes(StandardCharsets.UTF_8));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue