Created
April 19, 2011 21:04
-
-
Save peakpg/929652 to your computer and use it in GitHub Desktop.
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
private String encodeToMD5(String message) throws java.io.UnsupportedEncodingException, NoSuchAlgorithmException{ | |
byte[] bytesOfMessage = message.getBytes("UTF-8"); | |
MessageDigest md = MessageDigest.getInstance("MD5"); | |
byte[] messageDigest = md.digest(bytesOfMessage); | |
BigInteger number = new BigInteger(1, messageDigest); | |
String hashtext = number.toString(16); | |
// Now we need to zero pad it if you actually want the full 32 chars. | |
while (hashtext.length() < 32) { | |
hashtext = "0" + hashtext; | |
} | |
return hashtext; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment