You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

59 line
1.2 KiB

  1. using System;
  2. using System.Collections.ObjectModel;
  3. namespace SUISS.Cloud.Crypto
  4. {
  5. public class HmacSha256
  6. {
  7. public HmacSha256(byte[] key)
  8. {
  9. this._key = new byte[64];
  10. if (key.Length > 64)
  11. {
  12. ReadOnlyCollection<byte> readOnlyCollection = Sha256.HashBytes(new object[]
  13. {
  14. key
  15. });
  16. readOnlyCollection.CopyTo(this._key, 0);
  17. }
  18. else
  19. {
  20. Array.Copy(key, this._key, key.Length);
  21. }
  22. }
  23. public byte[] ComputeHash(byte[] message)
  24. {
  25. byte[] array = new byte[64];
  26. Array.Copy(this._key, array, 64);
  27. byte[] array2 = new byte[64];
  28. Array.Copy(this._key, array2, 64);
  29. for (int i = 0; i < 64; i++)
  30. {
  31. byte[] array3 = array;
  32. int num = i;
  33. array3[num] ^= 92;
  34. byte[] array4 = array2;
  35. int num2 = i;
  36. array4[num2] ^= 54;
  37. }
  38. ReadOnlyCollection<byte> readOnlyCollection = Sha256.HashBytes(new object[]
  39. {
  40. array,
  41. Sha256.HashBytes(new object[]
  42. {
  43. array2,
  44. message
  45. })
  46. });
  47. byte[] array5 = new byte[readOnlyCollection.Count];
  48. readOnlyCollection.CopyTo(array5, 0);
  49. return array5;
  50. }
  51. private const int BlockSize = 64;
  52. private byte[] _key;
  53. }
  54. }