MD5加密的本质就是把字符串的每个字节转化为int型再转化为对应的十六进制,然后存入StringBuilder中!
class Md5Utils { public static String getMD5String(String password) { try { MessageDigest digest = MessageDigest.getInstance("md5"); byte[] result = digest.digest(password.getBytes()); StringBuilder sb = new StringBuilder(); for (byte b : result) { int i = b & 0xff; // 加盐int i = b & 0xfe; String str = Integer.toHexString(i); if (str.length() == 1) { sb.append("0"); } sb.append(str); } return sb.toString(); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); return ""; } } }