C#的MD5加密
2010-08-09 15:30 ※森林小居※ 阅读(360) 评论(0) 编辑 收藏 举报以下代码对一个字符串加密,应该也支持中文!
public static string GetMD5(string str)
{
byte[] b=System.Text.Encoding.Default.GetBytes(str);
b=new System.Security.Cryptography.MD5CryptoServiceProvider().ComputeHash(b);
string ret="";
for(int i=0;i<b.Length;i++)
{
ret+=b[i].ToString ("x").PadLeft(2,'0');
}
return ret;
}
或者是:
String Password = "Test";
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(Password, "Md5");