首页 > 代码库 > MD5加密算法

MD5加密算法

  

 1 // MD5加密,32位 2     public static String MD5(String str) { 3         MessageDigest md5 = null; 4         try { 5             md5 = MessageDigest.getInstance("MD5"); 6         } catch (Exception e) { 7             e.printStackTrace(); 8             return ""; 9         }10         char[] charArray = str.toCharArray();11         byte[] byteArray = new byte[charArray.length];12         for (int i = 0; i < charArray.length; i++) {13             byteArray[i] = (byte) charArray[i];14         }15         byte[] md5Bytes = md5.digest(byteArray);16         StringBuffer hexValue = http://www.mamicode.com/new StringBuffer();17         for (int i = 0; i < md5Bytes.length; i++) {18             int val = ((int) md5Bytes[i]) & 0xff;19             if (val < 16) {20                 hexValue.append("0");21             }22             hexValue.append(Integer.toHexString(val));23         }24         return hexValue.toString();25     }
View Code

 

MD5加密算法