AdolphYang

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

MD5加密 及获得密码盐

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Configuration;
 4 using System.Linq;
 5 using System.Security.Cryptography;
 6 using System.Text;
 7 using System.Threading.Tasks;
 8 
 9 namespace WinForm_UserInfo
10 {
11     public class EncryptPwd
12     {
13         /// <summary>
14         /// 获取密码盐
15         /// </summary>
16         /// <returns>返回密码盐</returns>
17         public static string GetPwdSalt()
18         {
19             string pwdSalt = ConfigurationManager.AppSettings["pwdSalt"];
20             return pwdSalt;
21         }
22 
23         /// <summary>
24         /// 加密
25         /// </summary>
26         /// <param name="str">原始密码</param>
27         /// <returns>加密密码</returns>
28         public static string EncryptPassword(string str)
29         {
30             byte[] bytes = Encoding.Default.GetBytes(str);
31             MD5 md5 = new MD5CryptoServiceProvider();
32             byte[] newBytes = md5.ComputeHash(bytes);
33             string newStr = BitConverter.ToString(newBytes).Replace("-","");
34             return newStr;
35         }
36     }
37 }

 

posted on 2015-08-19 13:34  AdolphYang  阅读(740)  评论(0编辑  收藏  举报