Encoder.cs 535 B

1234567891011121314151617181920
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Security.Cryptography;
  4. using System.Text;
  5. namespace Bowin.Common.HmacSHA1
  6. {
  7. public class HMACSHA1Encoder
  8. {
  9. public static string Encode(string key, string text)
  10. {
  11. var keyByte = Encoding.UTF8.GetBytes(key);
  12. var textByte = Encoding.UTF8.GetBytes(text);
  13. HMACSHA1 hmac = new HMACSHA1(keyByte);
  14. hmac.Initialize();
  15. return Convert.ToBase64String(hmac.ComputeHash(textByte));
  16. }
  17. }
  18. }