//方法一
using System.Security;
using System.Security.Principal;
using System.Security.Cryptography;
using System.Text;
/// <summary>
/// 加密函数
/// </summary>
public string Encrypt(string password)
{
///获取Byte数组
Byte[] clearBytes = new UnicodeEncoding().GetBytes(password);
///获取Hash值
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
///获取加密后的信息
return BitConverter.ToString(hashedBytes);
}
//加密前的字串: admin
//加密后的结果: 19-A2-85-41-44-B6-3A-8F-76-17-A6-F2-25-01-9B-12
//方法二
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("要加密的字符串", System.Web.Configuration.FormsAuthPasswordFormat.MD5.ToString());
using System.Security;
using System.Security.Principal;
using System.Security.Cryptography;
using System.Text;
/// <summary>
/// 加密函数
/// </summary>
public string Encrypt(string password)
{
///获取Byte数组
Byte[] clearBytes = new UnicodeEncoding().GetBytes(password);
///获取Hash值
Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
///获取加密后的信息
return BitConverter.ToString(hashedBytes);
}
//加密前的字串: admin
//加密后的结果: 19-A2-85-41-44-B6-3A-8F-76-17-A6-F2-25-01-9B-12
//方法二
System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile("要加密的字符串", System.Web.Configuration.FormsAuthPasswordFormat.MD5.ToString());