Last active
March 10, 2019 12:22
-
-
Save ezhov-da/3155f62593b32a854a4d1e364ca30eb7 to your computer and use it in GitHub Desktop.
java md5
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
[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