添加引用:using System.Security.Cryptography;
代码:
class Md5Cyption
{
public static string Encrypt16(string strPwd)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(strPwd)), 4, 8);
t2 = t2.Replace("-", "");
return t2.ToLower();
}
public static string Encrypt32(string strPwd)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.Default.GetBytes(strPwd);
byte[] md5data = md5.ComputeHash(data);
md5.Clear();
string str = "";
for (int i = 0; i < md5data.Length - 1; i++)
{
str += md5data[i].ToString("x").PadLeft(2, '0');
}
return str.ToLower();
}
}