Md5加密

32位MD5加密
public static String enMD5(String str){
MessageDigest digest = null;
try {
digest = MessageDigest.getInstance("MD5");
digest.reset();
digest.update(str.getBytes("utf-8"));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
byte[] byteArray = digest.digest();
StringBuffer md5StrBuff = new StringBuffer("");
for (int j = 0; j < byteArray.length; j++) {
if (Integer.toHexString(0xFF & byteArray[j]).length() == 1) 
                md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[j])); 
            else 
                md5StrBuff.append(Integer.toHexString(0xFF & byteArray[j]));
}
return md5StrBuff.toString();
}
}

你可能感兴趣的:(MD5加密)