懒羊羊
2023-12-28 e46d3baaf3e8d7d85f4bafec3aad75e52b078408
提交 | 用户 | 时间
e46d3b 1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Security.Cryptography;
5 using System.Text;
6 using System.Threading.Tasks;
7
8 namespace YX.Common.DotNetEncrypt
9 {
10     /// <summary>
11     /// MD5加密帮助类
12     /// </summary>
13     public class Md5Helper
14     {
15         /// <summary>
16         /// MD5 32位加密
17         /// </summary>
18         /// <param name="str"></param>
19         /// <returns></returns>
20        public static string Md5(string str)
21         {
22             string cl = str;
23             string pwd = "";
24             MD5 md5 = MD5.Create();//实例化一个md5对像
25             // 加密后是一个字节类型的数组,这里要注意编码UTF8/Unicode等的选择 
26             byte[] s = md5.ComputeHash(Encoding.UTF8.GetBytes(cl));
27             // 通过使用循环,将字节类型的数组转换为字符串,此字符串是常规字符格式化所得
28             for (int i = 0; i < s.Length; i++)
29             {
30                 // 将得到的字符串使用十六进制类型格式。格式后的字符是小写的字母,如果使用大写(X)则格式后的字符是大写字符
31                 pwd = pwd + s[i].ToString("X");
32
33             }
34             return pwd;
35         }
36     }
37
38 }