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

Md5Util

时间:2017-08-11 17:50:14      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:工具类   color   tostring   bsp   技术   view   span   throw   open   

技术分享
 1 package cn.fraudmetrix.octopus.horai.biz.utils;
 2 
 3 import java.security.MessageDigest;
 4 import java.security.NoSuchAlgorithmException;
 5 
 6 public class Md5Util {
 7     //静态方法,便于作为工具类
 8     public static String getMd5(String plainText) throws NoSuchAlgorithmException {
 9         MessageDigest md = MessageDigest.getInstance("MD5");
10         md.update(plainText.getBytes());
11         byte b[] = md.digest();
12         int i;
13         StringBuffer buf = new StringBuffer("");
14         for (int offset = 0; offset < b.length; offset++) {
15             i = b[offset];
16             if (i < 0)
17                 i += 256;
18             if (i < 16)
19                 buf.append("0");
20             buf.append(Integer.toHexString(i));
21         }
22         //32位加密  
23         return buf.toString();
24         // 16位的加密
25         //return buf.toString().substring(8, 24);
26     }
27 }
View Code

 

Md5Util

标签:工具类   color   tostring   bsp   技术   view   span   throw   open   

原文地址:http://www.cnblogs.com/hunt/p/7347105.html

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