c# md5 加密

 1   public class MD5Utils
 2 {
 3     public string ComputeHash(string input)
 4     {
 5         using (MD5 md5 = MD5.Create())
 6         {
 7             // 将输入字符串转换为字节数组
 8             byte[] inputBytes = Encoding.UTF8.GetBytes(input);
 9 
10             // 计算 MD5 哈希值
11             byte[] hashBytes = md5.ComputeHash(inputBytes);
12 
13             // 将字节数组转换为十六进制字符串
14             StringBuilder sb = new StringBuilder();
15             for (int i = 0; i < hashBytes.Length; i++)
16             {
17                 sb.Append(hashBytes[i].ToString("x2"));
18             }
19 
20             return sb.ToString();
21         }
22     }
23 }

 

posted @ 2023-07-27 20:44  赵三毛  阅读(10)  评论(0编辑  收藏  举报