Created
April 13, 2016 07:28
-
-
Save hvalls/ff533b6c2459d9dfaf04518ae25e0327 to your computer and use it in GitHub Desktop.
MD5 encryption in Android
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
import java.io.UnsupportedEncodingException; | |
import java.math.BigInteger; | |
import java.security.MessageDigest; | |
import java.security.NoSuchAlgorithmException; | |
class MD5 { | |
public String encrypt(String token) { | |
int RESULT_LENGTH = 16; | |
MessageDigest cript; | |
try { | |
cript = MessageDigest.getInstance("MD5"); | |
} catch (NoSuchAlgorithmException e) { | |
throw new RuntimeException(e); | |
} | |
cript.reset(); | |
try { | |
cript.update(token.getBytes("utf8")); | |
} catch (UnsupportedEncodingException e) { | |
throw new RuntimeException(e); | |
} | |
return new BigInteger(1, cript.digest()).toString(RESULT_LENGTH); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment