public class MD5Util {
public static String getMD5(String str) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
} catch (NoSuchAlgorithmException e) {
return "";
}
byte[] input = str.getBytes();
byte[] buff = md.digest(input);
return bytesToHex(buff);
}
private static String bytesToHex(byte[] bytes) {
StringBuilder md5str = new StringBuilder();
int digital;
for (byte aByte : bytes) {
digital = aByte;
if (digital < 0) {
digital += 256;
}
if (digital < 16) {
md5str.append("0");
}
md5str.append(Integer.toHexString(digital));
}
return md5str.toString().toUpperCase();
}
}