Skip to content

Instantly share code, notes, and snippets.

@weitsai
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weitsai/8955252 to your computer and use it in GitHub Desktop.
Save weitsai/8955252 to your computer and use it in GitHub Desktop.
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