.net 下有个FormsAuthentication类,其中有个方法如下
//
// 摘要:
// 根据指定的密码和哈希算法生成一个适合于存储在配置文件中的哈希密码。
//
// 参数:
// password:
// 要进行哈希运算的密码。
//
// passwordFormat:
// 要使用的哈希算法。passwordFormat 是一个 String,表示 System.Web.Configuration.FormsAuthPasswordFormat
// 枚举值之一。
//
// 返回结果:
// 经过哈希运算的密码。
//
// 异常:
// System.ArgumentNullException:
// password 为 null。- 或 -passwordFormat 为 null。
//
// System.ArgumentException:
// passwordFormat 不是有效的 System.Web.Configuration.FormsAuthPasswordFormat 值。
public static string HashPasswordForStoringInConfigFile(string password, string passwordFormat);
根据此方法我们可以写个简单的MD5加密
/// <summary>
/// MD5加密
/// </summary>
/// <param name="password">要加密的字符串</param>
/// <returns>加密后的字符串</returns>
public static string MD5(string password)
{
return FormsAuthentication.HashPasswordForStoringInConfigFile(password, "MD5");
}