1 import java.io.UnsupportedEncodingException;
 2 import java.math.BigInteger;
 3 import java.security.MessageDigest;
 4 import java.security.NoSuchAlgorithmException;
 5 
 6 /**
 7  * MD5加密
 8  */
 9 public class MD5Util {
10     public static String getMD5Str(String str) {
11         byte[] digest = null;
12         try {
13             MessageDigest md5 = MessageDigest.getInstance("md5");
14             digest = md5.digest(str.getBytes("utf-8"));
15         } catch (NoSuchAlgorithmException e) {
16             e.printStackTrace();
17         } catch (UnsupportedEncodingException e) {
18             e.printStackTrace();
19         }
20         //16是表示转换为16进制数
21         String md5Str = new BigInteger(1, digest).toString(16);
22         return md5Str;
23     }
24 }

 

posted on 2022-01-17 14:38  奈文摩尔ゞ  阅读(3)  评论(0编辑  收藏  举报