MD5加密转32,大小写32位。16位
//需要加密的字符串:plainText
public class MD5Util {
public static String stringToMD5(String plainText) {
byte[] mdBytes = null;
try {
mdBytes = MessageDigest.getInstance("MD5").digest(
plainText.getBytes());
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("MD5算法不存在!");
}
String mdCode = new BigInteger(1, mdBytes).toString(16);
//得到16位加密字符
if(mdCode.length() < 32) {
int a = 32 - mdCode.length();
for (int i = 0; i < a; i++) {
mdCode = "0"+mdCode;
}
}
return mdCode.toUpperCase(); //返回32位大写加密字符
// return mdCode; // 默认返回32位小写加密字符
}
}