Created
June 25, 2015 17:56
-
-
Save fernandodev/7428f1328f4c2a1e9064 to your computer and use it in GitHub Desktop.
Android - Encrypt passwords with HMAC SHA512
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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