Skip to content

Instantly share code, notes, and snippets.

@ursimon
Created January 21, 2014 13:00
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 ursimon/8539579 to your computer and use it in GitHub Desktop.
Save ursimon/8539579 to your computer and use it in GitHub Desktop.
computes MD5 hash
public String computeMD5Hash(String password)
{
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(password.getBytes());
byte messageDigest[] = digest.digest();
StringBuffer MD5Hash = new StringBuffer();
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);
}
Logg.v("computeHash","MD5 hash generated is: " + " " + MD5Hash);
return MD5Hash.toString();
}
catch (NoSuchAlgorithmException e)
{
e.printStackTrace();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment