Skip to content

Instantly share code, notes, and snippets.

@altmind
Created March 13, 2012 08:00
Show Gist options
  • Save altmind/2027529 to your computer and use it in GitHub Desktop.
Save altmind/2027529 to your computer and use it in GitHub Desktop.
class TestHMAC {
...
private String calculateMAC(byte[] inputBytes, String password) throws NoSuchAlgorithmException, InvalidKeyException {
SecretKeySpec signingKey = new SecretKeySpec(password.getBytes(), HMAC_SHA1_ALGORITHM);
Mac mac = Mac.getInstance(HMAC_SHA1_ALGORITHM);
mac.init(signingKey);
byte[] rawHmac = mac.doFinal(inputBytes);
return new String(Hex.encodeHex(rawHmac, true));
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment