Skip to content

Instantly share code, notes, and snippets.

@kgundula
Created August 28, 2015 08:58
Show Gist options
  • Save kgundula/4bbde439fc34edfa9292 to your computer and use it in GitHub Desktop.
Save kgundula/4bbde439fc34edfa9292 to your computer and use it in GitHub Desktop.
Java MD5 Hash Generator which is equivalent to PHP MD5()
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