Skip to content

Instantly share code, notes, and snippets.

@ezhov-da
Last active March 10, 2019 12:22
Show Gist options
  • Save ezhov-da/3155f62593b32a854a4d1e364ca30eb7 to your computer and use it in GitHub Desktop.
Save ezhov-da/3155f62593b32a854a4d1e364ca30eb7 to your computer and use it in GitHub Desktop.
java md5
[code:]java[:code]
import java.security.MessageDigest;
public class MD5CheckSum
{
public String getHash(String str)throws Exception {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(str.getBytes());
byte[] dataBytes = md.digest();
StringBuilder sb = new StringBuilder();
for (int i = 0; i < dataBytes.length; i++) {
sb.append(Integer.toString((dataBytes[i] & 0xff) + 0x100, 16).substring(1));
}
return sb.toString();
}
}
[/code]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment