1. 首先創建MD5的哈希算法。
((HashAlgorithm)System.Security.Cryptogrophy.CryptoConfig.CreateFromName("MD5")).ComputeHash(System.Text.UTF8.GetBytes(input))
2.計算哈希值
使用方法:ComputeHash(byte[] value);
3.轉化成字符串.
1protected virtual string HashMD5(string input)
2 {
3 byte[] result = ((HashAlgorithm)System.Security.Cryptography.CryptoConfig.CreateFromName("MD5")).ComputeHash(System.Text.Encoding.UTF8.GetBytes(input));
4 StringBuilder output = new StringBuilder(16);
5
6 for (int i = 0; i < result.Length; i++)
7 {
8 // convert from hexa-decimal to character
9 output.Append((result[i]).ToString( "x2", System.Globalization.CultureInfo.InvariantCulture));
10 }
11 return output.ToString();
12 }
13