Created
January 19, 2015 15:30
-
-
Save acacha/e87e3644b494cb9b2ae9 to your computer and use it in GitHub Desktop.
Java MD5 function
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
public String computeMD5Hash(String password){ | |
StringBuffer MD5Hash = new StringBuffer(); | |
try { | |
// Create MD5 Hash | |
MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); | |
digest.update(password.getBytes()); | |
byte messageDigest[] = digest.digest(); | |
for (int i = 0; i < messageDigest.length; i++) | |
{ | |
String h = Integer.toHexString(0xFF & messageDigest[i]); | |
while (h.length() < 2) | |
h = "0" + h; | |
MD5Hash.append(h); | |
} | |
} | |
catch (NoSuchAlgorithmException e) | |
{ | |
e.printStackTrace(); | |
} | |
return MD5Hash.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment