Skip to content

Instantly share code, notes, and snippets.

@acacha
Created January 19, 2015 15:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acacha/e87e3644b494cb9b2ae9 to your computer and use it in GitHub Desktop.
Save acacha/e87e3644b494cb9b2ae9 to your computer and use it in GitHub Desktop.
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