Skip to content

Instantly share code, notes, and snippets.

@hvalls
Created April 13, 2016 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hvalls/ff533b6c2459d9dfaf04518ae25e0327 to your computer and use it in GitHub Desktop.
Save hvalls/ff533b6c2459d9dfaf04518ae25e0327 to your computer and use it in GitHub Desktop.
MD5 encryption in Android
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