码迷,mamicode.com
首页 > 编程语言 > 详细

.net下MD5算法和加盐

时间:2015-04-25 16:23:08      阅读:170      评论:0      收藏:0      [点我收藏+]

标签:

MD5方法:

public static string GetMD5(string sDataIn)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            byte[] bytValue, bytHash;
            bytValue = System.Text.Encoding.UTF8.GetBytes(sDataIn);
            bytHash = md5.ComputeHash(bytValue);
            md5.Clear();
            string sTemp = "";
            for (int i = 0; i < bytHash.Length; i++)
            {
                sTemp += bytHash[i].ToString("X").PadLeft(2, ‘0‘);
            }
            return sTemp.ToLower();
        }

密码加盐
        public static string GetPasswordSalt()
        {
            string getPasswordSalt= ConfigurationManager.AppSettings["passwordSalt"];
            return getPasswordSalt;
        }

passwordSalt就是所谓的盐,其内容存放在App.config文件里,app中代码:

<configuration>
  <appSettings>
    <add key="passwordSalt" value="1234"/>//1234为盐,用参数passwordSalt表示
  </appSettings>
</configuration>

.net下MD5算法和加盐

标签:

原文地址:http://www.cnblogs.com/hcrs/p/4455980.html

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