使用using System.Security.Cryptography进行md5加密;
private string encrypt(string src)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] dir = md5.ComputeHash(UTF8Encoding.UTF8.GetBytes(src));
StringBuilder resualt = new StringBuilder();
for (int i = 0; i < dir.Length; i++)
{
string x = Convert.ToString(dir[i], 16);
if (x.Length < 2)
x = "0" + x;
resualt.Append(x);
}
return resualt.ToString();
}
使用System.Web.Security进行md5加密
public string md5(string str, int code)
{
if (code == 16)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower().Substring(8, 16);
}
if (code == 32)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5");
}
return "00000000000000000000000000000000";
}
浙公网安备 33010602011771号