Skip to content

Instantly share code, notes, and snippets.

@fernandodev
Created June 25, 2015 17:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fernandodev/7428f1328f4c2a1e9064 to your computer and use it in GitHub Desktop.
Save fernandodev/7428f1328f4c2a1e9064 to your computer and use it in GitHub Desktop.
Android - Encrypt passwords with HMAC SHA512
/**
* You have to use: compile 'commons-codec:commons-codec:1.4'
* as dependency
*/
public static String HMACSHA512(String value, String securityHmac) throws UnsupportedEncodingException,
NoSuchAlgorithmException, InvalidKeyException {
SecretKeySpec key = new SecretKeySpec((securityHmac).getBytes("UTF-8"), "HmacSHA512");
Mac mac = Mac.getInstance("HmacSHA512");
mac.init(key);
byte[] bytes = mac.doFinal(value.getBytes());
return Hex.encodeHexString(bytes);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment