联系我们

为客户提供超预期的高品质网站设计!

md5加密

2017-1-4 0:00:00

//-------------------方法一 在.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>");


上一条新闻:asp access 在插入一条记录后,如何获得该记录的ID
下一条新闻:asp.net 自定义类

 

4009-606-208 54057491 info@