调用这个类就行了
using System.Text;
using System.Security.Cryptography;
namespace class1
{
[System.Diagnostics.DebuggerStepThroughAttribute()]
public static class MD5Encode
{
//用md5 hash 字符串
public static string MD5Hash(string str)
{
ASCIIEncoding ASC = new ASCIIEncoding();
byte[] arrPwd = ASC.GetBytes(str);
MD5 md5 = new MD5CryptoServiceProvider();
byte[] arrHashPwd = md5.ComputeHash(arrPwd);
//转成字符串,表示十六进制值
string sHashPwd = "";
foreach (byte b in arrHashPwd)
{
if (b < 16)
sHashPwd = sHashPwd + "0" + b.ToString("x");
else
sHashPwd = sHashPwd + b.ToString("x");
}
return sHashPwd;
}
}
}