怎样在ASP.NET中用MD5对数据加密,麻烦些详细点谢谢
2个回答
展开全部
using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
/// <summary>
/// 使用MD5算法加密(不可逆,无法解密)
/// 把此方法加入CS页面然后直接调用就行了
/// </summary>
/// <param name="password">明文</param>
/// <returns>密文</returns>
public static string EncryptionMD5(string password)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] bytes = new byte[16];
System.Text.ASCIIEncoding asc = new System.Text.ASCIIEncoding();
bytes = md5.ComputeHash(asc.GetBytes(password));
return Convert.ToBase64String(bytes);
}
/// <summary>
/// 使用SHA1算法求加密(不可逆,无法解密)
/// </summary>
/// <param name="text">明文</param>
/// <returns>密文</returns>
public static string EncryptionSHA1(string text)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(text,"SHA1");
}
using System.Collections.Generic;
using System.Text;
using System.Web;
/// <summary>
/// 使用MD5算法加密(不可逆,无法解密)
/// 把此方法加入CS页面然后直接调用就行了
/// </summary>
/// <param name="password">明文</param>
/// <returns>密文</returns>
public static string EncryptionMD5(string password)
{
System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] bytes = new byte[16];
System.Text.ASCIIEncoding asc = new System.Text.ASCIIEncoding();
bytes = md5.ComputeHash(asc.GetBytes(password));
return Convert.ToBase64String(bytes);
}
/// <summary>
/// 使用SHA1算法求加密(不可逆,无法解密)
/// </summary>
/// <param name="text">明文</param>
/// <returns>密文</returns>
public static string EncryptionSHA1(string text)
{
return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(text,"SHA1");
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询