HMACSha1加密方法

 1 /// <summary>
 2         /// HMAC加密
 3         /// </summary>
 4         /// <param name="EncryptText">加密内容</param>
 5         /// <param name="EncryptKey">密钥</param>
 6         /// <returns></returns>
 7         public static string ToHMacSha1(string EncryptText, string EncryptKey)
 8         {
 9             string result = "";
10 
11             try
12             {
13                 HMACSHA1 hmacsha1 = new HMACSHA1();
14                 hmacsha1.Key = System.Text.Encoding.UTF8.GetBytes(EncryptKey);
15                 byte[] dataBuffer = System.Text.Encoding.UTF8.GetBytes(EncryptText);
16                 byte[] hashBytes = hmacsha1.ComputeHash(dataBuffer);
17 
18                 result = Convert.ToBase64String(hashBytes);
19             }
20             catch (Exception ex)
21             {
22 
23             }
24 
25             return result;
26         }

      

【原文出处】http://www.51aras.com/?id=9

     

原文地址:https://www.cnblogs.com/61007257Steven/p/10953382.html