来自偶然的尘土
代码如风,常伴我身

简版的MD5工具类

 1 import java.security.MessageDigest;
 2 import sun.misc.BASE64Encoder;
 3 public class Md5ToString {
 4  
 5  
 6 import java.security.MessageDigest;
 7 import sun.misc.BASE64Encoder;
 8 public class Md5Tools{
 9  
10  /**
11   * md5加密
12   * @param old
13   * @return
14   * 
15   */
16  public static String Md5String(String old) {
17   try {
18    //java自带工具包MessageDigest
19    MessageDigest md5 = MessageDigest.getInstance("md5");
20    //实现Base64的编码
21    BASE64Encoder base64 = new BASE64Encoder();
22    //进行加密
23    String newStr = base64.encode(md5.digest(old.getBytes("utf-8")));
24    return newStr;//返回加密后的字符
25   } catch (Exception e) {
26    throw new RuntimeException(e);
27   }
28  }
29 }

 

 

 

posted on 2019-01-20 15:18  来自偶然的尘土  阅读(1805)  评论(0编辑  收藏  举报