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

     


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM