Java 实现32位MD5加密
MD5介绍【链接】
Java代码实现
1 public class Md5Util { 2 private String Md5Util(String s) { 3 try { 4 MessageDigest md = MessageDigest.getInstance("MD5"); 5 byte[] bytes = md.digest(s.getBytes("utf-8")); 6 return toHex(bytes); 7 } catch (Exception e) { 8 throw new RuntimeException(e); 9 } 10 } 11 12 private static String toHex(byte[] bytes) { 13 14 final char[] HEX_DIGITS = "0123456789abcdef".toCharArray(); 15 StringBuilder ret = new StringBuilder(bytes.length * 2); 16 for (int i = 0; i < bytes.length; i++) { 17 ret.append(HEX_DIGITS[(bytes[i] >> 4) & 0x0f]); 18 ret.append(HEX_DIGITS[bytes[i] & 0x0f]); 19 } 20 return ret.toString(); 21 } 22 }