Package com.gmt2001.security
Class HMAC
java.lang.Object
com.gmt2001.security.HMAC
Provides an easy interface to calculating an HMAC-SHA256
- Author:
- Søren Poulsen and gmt2001
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
calcHmacSha256
(byte[] secretKey, byte[] message) Calculates an HMAC-SHA256static String
calcHmacSha256
(String secretKey, String message) Calculates an HMAC-SHA256 and returns the MAC as a hex-encoded stringstatic boolean
compareHmacSha256
(byte[] secretKey, byte[] message, byte[] mac) Calculates an HMAC-SHA256 and compares it to an existing MACstatic boolean
compareHmacSha256
(String secretKey, String message, String mac) Calculates an HMAC-SHA256 and compares it to an existing MAC
-
Method Details
-
calcHmacSha256
public static byte[] calcHmacSha256(byte[] secretKey, byte[] message) Calculates an HMAC-SHA256- Parameters:
secretKey
- The secret keymessage
- The message to calculate the MAC on- Returns:
- the MAC
-
calcHmacSha256
Calculates an HMAC-SHA256 and returns the MAC as a hex-encoded string- Parameters:
secretKey
- The secret keymessage
- The message to calculate the MAC on- Returns:
- the MAC as a hex-encoded string
-
compareHmacSha256
public static boolean compareHmacSha256(byte[] secretKey, byte[] message, byte[] mac) Calculates an HMAC-SHA256 and compares it to an existing MAC- Parameters:
secretKey
- The secret keymessage
- The message to calculate the MAC onmac
- The MAC to compare to- Returns:
true
if the calculated MAC matches the provided MAC
-
compareHmacSha256
Calculates an HMAC-SHA256 and compares it to an existing MAC- Parameters:
secretKey
- The secret keymessage
- The message to calculate the MAC onmac
- The MAC to compare to- Returns:
true
if the calculated MAC matches the provided MAC
-