1 //1、加密成32位16进制字符串
2 protected string HashMD5_String(string str)
3 {
4 return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
5 }
6
7 //2、同上,增加偏移量
8
9 public string GetMD5(string sDataIn, string move)
10 {
11 System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
12 byte[] byt, bytHash;
13 byt = System.Text.Encoding.UTF8.GetBytes(move + sDataIn);
14 bytHash = md5.ComputeHash(byt);
15 md5.Clear();
16 string sTemp = "";
17 for (int i = 0; i < bytHash.Length; i++)
18 {
19 sTemp += bytHash[i].ToString("x").PadLeft(2, '0');
20 }
21 return sTemp;
22 }
23 //3、将字符串编码成ASCII数组后进行MD5加密,然后再编码成ASCII字符串
24 public static string MD5Encrypt(string strEnc)
25 {
26 string str = "加密失败!";
27 try
28 {
29
30 System.Security.Cryptography.MD5CryptoServiceProvider MD5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
31 str = ASCIIEncoding.ASCII.GetString(MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strEnc)));
32 return str;
33 }
34 catch (System.Exception ex)
35 {
36 throw (ex);
37 }
38 }