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