MD5加密
方法一:
string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5")//不截取字符串
或:string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5").Substring(8, 16);//截取字符串
如果该加密方法写在控制层里需添加引用System.Web,
并在类中添加using System.Web.Security;
方法二:
using System.Security.Cryptography;
//str是
public static string GetMD5String(string str)
{
MD5 md5 = MD5.Create();
byte[] b = Encoding.UTF8.GetBytes(str);
byte[] md5b = md5.ComputeHash(b);
md5.Clear();
StringBuilder sb = new StringBuilder();
foreach (var item in md5b)
{
sb.Append(item.ToString("x2"));
}
return sb.ToString();
}
注意:加密之后的字符串应与相比较的字符串大小写一致
方法一:
string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5")//不截取字符串
或:string password = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5").Substring(8, 16);//截取字符串
如果该加密方法写在控制层里需添加引用System.Web,
并在类中添加using System.Web.Security;
方法二:
using System.Security.Cryptography;
//str是
public static string GetMD5String(string str)
{
MD5 md5 = MD5.Create();
byte[] b = Encoding.UTF8.GetBytes(str);
byte[] md5b = md5.ComputeHash(b);
md5.Clear();
StringBuilder sb = new StringBuilder();
foreach (var item in md5b)
{
sb.Append(item.ToString("x2"));
}
return sb.ToString();
}
注意:加密之后的字符串应与相比较的字符串大小写一致
1万+

被折叠的 条评论
为什么被折叠?



