Skip to content

Instantly share code, notes, and snippets.

@mattiz
Created April 3, 2012 19:43
Show Gist options
  • Save mattiz/2295047 to your computer and use it in GitHub Desktop.
Save mattiz/2295047 to your computer and use it in GitHub Desktop.
public static String md5( String clearText ) {
MessageDigest md;
byte[] cipher;
StringBuilder hexString;
try {
md = java.security.MessageDigest.getInstance("MD5");
cipher = md.digest( clearText.getBytes( "UTF-8" ) );
hexString = new StringBuilder();
for( int i = 0; i < cipher.length; ++i ) {
hexString.append( Integer.toHexString((cipher[i] & 0xFF) | 0x100).substring(1,3) );
}
return hexString.toString();
} catch( NoSuchAlgorithmException e ) {
e.printStackTrace();
} catch( UnsupportedEncodingException e ) {
e.printStackTrace();
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment