MD5Provider 的摘要说明

 1 /// <summary>
 2     /// MD5Provider 的摘要说明
 3     /// </summary>
 4     public class MD5Provider
 5     {
 6         private MD5Provider()
 7         {
 8         }
 9         /// <summary>
10         /// 计算指定字符串的MD5哈希值
11         /// </summary>
12         /// <param name="message">要进行哈希计算的字符串</param>
13         /// <returns></returns>
14         public static string Hash(string message)
15         {
16             if (string.IsNullOrEmpty(message))
17             {
18                 return string.Empty;
19             }
20             else
21             {
22                 MD5 md5 = MD5.Create();
23                 byte[] source = Encoding.UTF8.GetBytes(message);
24                 byte[] result = md5.ComputeHash(source);
25                 StringBuilder buffer = new StringBuilder(result.Length);
26 
27                 for (int i = 0; i < result.Length; i++)
28                 {
29                     buffer.Append(result[i].ToString("x"));//将byte值转换成十六进制字符串
30                 }
31                 return buffer.ToString() ;
32             }
33 
34         }
35     }

 

posted @ 2016-09-23 09:04  百年明日能几何  阅读(242)  评论(0编辑  收藏  举报