发布于 2016-05-28 07:37:34 | 131 次阅读 | 评论: 1 | 来源: 网友投递
ASP.NET
ASP.NET 是.NET FrameWork的一部分,是一项微软公司的技术,是一种使嵌入网页中的脚本可由因特网服务器执行的服务器端脚本技术,它可以在通过HTTP请求文档时再在Web服务器上动态创建它们。 指 Active Server Pages(动态服务器页面) ,运行于 IIS(Internet Information Server 服务,是Windows开发的Web服务器)之中的程序 。
Response.Write(FormsAuthentication.HashPasswordForStoringInConfigFile("www.mzwu.com", "MD5"));
//结果:D66E1F138689B9B5AA4C520D9EAFFB61
Response.Write(MD5("www.mzwu.com",32))
'结果:d66e1f138689b9b5aa4c520d9eaffb61
Response.Write(FormsAuthentication.HashPasswordForStoringInConfigFile("木子屋", "MD5"));
//结果:34D9CBD5164C47058DFA3AF832E2D1DC
Response.Write(MD5("木子屋",32))
'结果:0a40a90190da023ae7aa17771663a41e
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
Response.Write(BitConverter.ToString(MD5.ComputeHash(Encoding.GetEncoding("gb2312").GetBytes("木子屋"))).Replace("-", ""));
//结果:0A40A90190DA023AE7AA17771663A41E
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
Response.Write(BitConverter.ToString(MD5.ComputeHash(Encoding.GetEncoding("utf-8").GetBytes("木子屋"))).Replace("-", ""));
//结果:34D9CBD5164C47058DFA3AF832E2D1DC
/**//// <summary>
/// 对字符串进行MD5加密
/// </summary>
/// <param name="text">要加密的字符串</param>
/// <param name="charset">字符串编码格式</param>
/// <example>str = MD5("木子屋","gb2312");</example>
/// <returns></returns>
public string MD5(string text, string charset)
{
return (MD5(text, charset, false));
}
/**//// <summary>
/// 对字符串或参数值进行MD5加密
/// </summary>
/// <param name="text">要加密的字符串或参数名称</param>
/// <param name="charset">字符串编码格式</param>
/// <param name="isArg">加密字符串类型 true:参数值 false:字符串</param>
/// <returns></returns>
public string MD5(string text, string charset, bool isArg)
{
try
{
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
if (isArg)
{
NameValueCollection Collect = HttpUtility.ParseQueryString(Request.Url.Query, Encoding.GetEncoding(charset));//使用Collect接收参数值
if (Collect[text] != null)
{
return BitConverter.ToString(MD5.ComputeHash(Encoding.GetEncoding(charset).GetBytes(Collect[text].ToString()))).Replace("-", "");
}
}
else
{
return BitConverter.ToString(MD5.ComputeHash(Encoding.GetEncoding(charset).GetBytes(text))).Replace("-", "");
}
}
catch { }
return string.Empty;
}
using System.Text;
using System.Web.Security;
using System.Security.Cryptography;
using System.Collections.Specialized;