码迷,mamicode.com
首页 > Web开发 > 详细

asp.neti 加密三种方式

时间:2015-02-10 15:14:32      阅读:116      评论:0      收藏:0      [点我收藏+]

标签:

public string Get_MD5_Method1(string strSource)
        {
            System.Security.Cryptography.MD5 md5 = new 

System.Security.Cryptography.MD5CryptoServiceProvider();
            //获取密文字节数组 
            byte[] bytResult = md5.ComputeHash(System.Text.Encoding.Default.GetBytes

(strSource));
            //转换成字符串,并取9到25位 
            string strResult = BitConverter.ToString(bytResult, 4, 8);
            //转换成字符串,32位 
            //string strResult = BitConverter.ToString(bytResult); 

            //BitConverter转换出来的字符串会在每个字符中间产生一个分隔符,需要去除掉 
            strResult = strResult.Replace("-", "");
            return strResult; 
        }
--------------------------------------------第二种
  public string Get_MD5_Method2(string strSource)
        {
            string strResult = "";

            //Create 
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create

();

            //注意编码UTF8、UTF7、Unicode等的选择 
            byte[] bytResult = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes

(strSource));

            //字节类型的数组转换为字符串 
            for (int i = 0; i < bytResult.Length; i++)
            {
                //16进制转换 
                strResult = strResult + bytResult[i].ToString("X");
            }
            return strResult;
        } 

-------------------------简写--------------
public string Get_MD5_Method3(string strSource) 
{ 
 return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile

(strSource, "MD5"); 
} 

 

asp.neti 加密三种方式

标签:

原文地址:http://www.cnblogs.com/codemouserman/p/4283815.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!