码迷,mamicode.com
首页 > 其他好文 > 详细

MD5加密方法

时间:2014-10-16 16:14:22      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   os   ar   for   sp   div   

项目中的一个方法,32位小写加密。

 

 1     public static String encryptByMD5(String str) {
 2         MessageDigest messageDigest = null;
 3 
 4         try {
 5             messageDigest = MessageDigest.getInstance("MD5");
 6             messageDigest.reset();
 7             messageDigest.update(str.getBytes("UTF-8"));
 8         } catch (NoSuchAlgorithmException e) {
 9             e.printStackTrace();
10         } catch (UnsupportedEncodingException e) {
11             e.printStackTrace();
12         }
13 
14         byte[] byteArray = messageDigest.digest();
15         StringBuffer md5StrBuff = new StringBuffer();
16 
17         for (int i = 0; i < byteArray.length; i++) {
18             if (Integer.toHexString(0xFF & byteArray[i]).length() == 1) {
19                 md5StrBuff.append("0").append(Integer.toHexString(0xFF & byteArray[i]));
20             } else {
21                 md5StrBuff.append(Integer.toHexString(0xFF & byteArray[i]));
22             }
23         }
24 
25         return md5StrBuff.toString();
26     }

 

MD5加密方法

标签:style   blog   color   io   os   ar   for   sp   div   

原文地址:http://www.cnblogs.com/wwawp66/p/4028814.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!