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 StringcalcHmacSha256(String secretKey, String message) Calculates an HMAC-SHA256 and returns the MAC as a hex-encoded stringstatic booleancompareHmacSha256(byte[] secretKey, byte[] message, byte[] mac) Calculates an HMAC-SHA256 and compares it to an existing MACstatic booleancompareHmacSha256(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:
trueif 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:
trueif the calculated MAC matches the provided MAC
-