/**
* encrypt32
*
* @param encryptStr
* @return String
*/
public static String encrypt32(String encryptStr) {
MessageDigest md5;
try {
md5 = MessageDigest.getInstance("MD5");
byte[] md5Bytes = md5.digest(encryptStr.getBytes());
StringBuffer hexValue = new StringBuffer();
for (int i = 0; i < md5Bytes.length; i++) {
int val = ((int) md5Bytes[i]) & 0xff;
if (val < 16)
hexValue.append("0");
hexValue.append(Integer.toHexString(val));
}
encryptStr = hexValue.toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
return encryptStr;
}
/**
* encrypt16
*
* @param encryptStr
* @return String
*/
public static String encrypt16(String encryptStr) {
return encrypt32(encryptStr).substring(8, 24);
}
java 中16位和32位MD5小写加密
最新推荐文章于 2024-04-05 10:30:00 发布