VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > C#教程 >
  • c# md5 加密

制作者:剑锋冷月 单位:无忧统计网,www.51stat.net
 

  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



相关教程