数据加密方法小结:
一. 使用FormsAuthentication.HashPasswordForStoringInConfigFile 方法
1. if (Page.IsValid)
{
string hashMethod = "";
if (md5.Checked)
{
hashMethod = "MD5";
}
else
{
hashMethod = "SHA1";
}
string hashedPassword =
FormsAuthentication.HashPasswordForStoringInConfigFile(password.Text, hashMethod);
result.Text = "<credentials passwordFormat=/"" + hashMethod +"/"><br />" +
" <user name=/"" + Server.HtmlEncode(userName.Text) + "/" password=/"" +
hashedPassword + "/" /><br />" + "</credentials>";
}
else
{
result.Text = "There was an error on the page.";
}
2.实例2:
public static string MD5Hash(this string s)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(s,"MD5");
}