1. 程式人生 > >Java 實現32位MD5加密

Java 實現32位MD5加密

https utf baidu static post AD pos byte tar

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 }

Java 實現32位MD5加密