下面分享一下md5加密方法:
public static String MD5(String str){
MessageDigest md5 = null;
StringBuffer hexValue = new StringBuffer();
try {
md5 = MessageDigest.getInstance("MD5");
char[] charArray = str.toCharArray();
byte[] byteArray = new byte[charArray.length];
for (int i = 0; i < charArray.length; i++) {
byteArray[i] = (byte) charArray[i];
}
byte[] md5Bytes = md5.digest(byteArray);
for (int j = 0; j < md5Bytes.length; j++) {
int val = ((int)md5Bytes[j]) & 0xff;
if (val < 16) {
hexValue.append("0");
}
hexValue.append(Integer.toHexString(val));
}
} catch (Exception e) {
e.printStackTrace();
}
return hexValue.toString();
}
public static void main(String[] args) {
//MD5加密字符串
System.out.println(SystemUtils.MD5(SystemUtils.MD5("111111")).toUpperCase());
}