Skip to content

Instantly share code, notes, and snippets.

@acacha
Created Jan 19, 2015
Embed
What would you like to do?
Java MD5 function
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