Md5util.java public class Md5util {private static StringBuffer stringBuffer;public static String encoder(String psd){psd = "mutisafe" + psd + "@leafotto.tk";try {//指定加密算法MessageDigest digest = MessageDigest.getInstance("MD5");//将
public class Md5util { private static StringBuffer stringBuffer; public static String encoder(String psd){ psd = "mutisafe" + psd + "@leafotto.tk"; try { //指定加密算法 MessageDigest digest = MessageDigest.getInstance("MD5"); //将需要加密的字符串转换成byte类型的数组,然后进行随机哈希 byte[] bs = digest.digest(psd.getBytes()); //循环遍历bs,然后让其生成32位字符串,固定写法 stringBuffer = new StringBuffer(); for(byte b : bs){ int i = b & 0xff; String hexString = Integer.toHexString(i); if(hexString.length() < 2){ hexString = "0" + hexString; } //拼接字符串 stringBuffer.append(hexString); } return stringBuffer.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return ""; } }