Created
August 28, 2015 08:58
-
-
Save kgundula/4bbde439fc34edfa9292 to your computer and use it in GitHub Desktop.
Java MD5 Hash Generator which is equivalent to PHP MD5()
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 static String md5Hash (String input) throws NoSuchAlgorithmException { | |
String result = input; | |
if(input != null) { | |
MessageDigest messageDigest = MessageDigest.getInstance("MD5"); | |
messageDigest.update(input.getBytes()); | |
BigInteger hash = new BigInteger(1, messageDigest.digest()); | |
result = hash.toString(16); | |
while (result.length() < 32) { | |
result = "0"+result; | |
} | |
} | |
return result; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment