Last active
August 29, 2015 13:56
-
-
Save fada21/8805907 to your computer and use it in GitHub Desktop.
Create a MD5-Hash and Dump as a Hex String
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 String md5(String s) { | |
try { | |
// Create MD5 Hash | |
MessageDigest digest = java.security.MessageDigest.getInstance("MD5"); | |
digest.update(s.getBytes()); | |
byte messageDigest[] = digest.digest(); | |
// Create Hex String | |
StringBuffer hexString = new StringBuffer(); | |
for (int i=0; i<messageDigest.length; i++) | |
hexString.append(Integer.toHexString(0xFF & messageDigest[i])); | |
return hexString.toString(); | |
} catch (NoSuchAlgorithmException e) { | |
e.printStackTrace(); | |
} | |
return ""; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment