Last active
August 29, 2015 13:56
-
-
Save weitsai/8955252 to your computer and use it in GitHub Desktop.
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 class Test { | |
public static void main(String[] argv) { | |
MessageDigest md = MessageDigest.getInstance("MD5"); | |
md.update("test"); | |
// md5("test") | |
System.out.pringln(toHexString(md.digest())); | |
// md5(md5("test")) | |
System.out.pringln(toHexString(md.digest())); | |
} | |
private static String toHexString(byte[] in) { | |
StringBuilder hexString = new StringBuilder(); | |
for (int i = 0; i < in.length; i++) { | |
String hex = Integer.toHexString(0xFF & in[i]); | |
if (hex.length() == 1) { | |
hexString.append('0'); | |
} | |
hexString.append(hex); | |
} | |
return hexString.toString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment