
using System;
using System.Security.Cryptography;
using System.Text;
//计算 MD5 哈希值是用 MD5CryptoServiceProvider().ComputeHash 这个方法。由于 ComputeHash 方法需要传入的参数是 Byte 类型,而不是 String 类型。因此要将传入的数据先从字符串变成一个 Byte 数组先把字符转成Byte数组
string str = "111111"; //你要加密的字符串
byte[] buffer1 = Encoding.Unicode.GetBytes(str.ToCharArray());
MD5 md1 = new MD5CryptoServiceProvider();
buffer1 = md1.ComputeHash(buffer1);
string mValue = string.Empty;
byte[] buffer2 = buffer1;
//将此类值存储为一个十六进制字符串是非常有用的
for (int num2 = 0; num2 < buffer2.Length; num2++)
{
byte num1 = buffer2[num2]; //循环得到数组字符
mValue = mValue + num1.ToString("x");//然后转成16进制,递加起来
}详情见:http://support.microsoft.com/kb/307020/zh-cn

浙公网安备 33010602011771号