import java.security.MessageDigest;
public class MD5Util {
public static String encrypt(String str) {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest(str.getBytes());
return byteToString(digest);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
private static String byteToString(byte[] digest) {
StringBuffer sb = new StringBuffer();
String tempStr = "";
for (int i = 0; i < digest.length; ++i) {
tempStr = (Integer.toHexString(digest[i] &0xFF));
if (tempStr.length() == 1) {
sb.append("0").append(tempStr);
} else {
sb.append(tempStr);
}
}
return sb.toString().toUpperCase();
}
public static void main(String[] args) {
System.out.println(MD5Util.encrypt("Biao"));
}
}