md5加密
//-------------------方法一 在.net4.0以上-----------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Security;
public partial class _testDel : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string p = "";
System.Security.Cryptography.MD5 md5 =new System.Security.Cryptography.MD5CryptoServiceProvider();
byte[] bytResult = md5.ComputeHash(System.Text.Encoding.Default.GetBytes(p));
//转换成字符串,并取9到25位
string strResult = BitConverter.ToString(bytResult, 4, 8);
//转换成字符串,32位
//string strResult = BitConverter.ToString(bytResult);
//BitConverter转换出来的字符串会在每个字符中间产生一个分隔符,需要去除掉
strResult = strResult.Replace("-", "");
strResult = strResult.ToLower();//小写字母
Response.Write(strResult);
}
}
//-------------------方法一 在.net2.0-----------------------------
string p = "";
string s = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(p, "md5").ToString();
Response.Write("<div>"+s+"</div>");
Response.Write("<div>" + s.ToLower().Substring(8, 16) + "</div>");