HmacAlgorithm.cs 806 B

1234567891011121314151617181920212223242526272829303132
  1. using System.Diagnostics.Contracts;
  2. using System.Security.Cryptography;
  3. namespace FxSsh.Algorithms
  4. {
  5. public class HmacAlgorithm
  6. {
  7. private readonly KeyedHashAlgorithm _algorithm;
  8. public HmacAlgorithm(KeyedHashAlgorithm algorithm, int keySize, byte[] key)
  9. {
  10. Contract.Requires(algorithm != null);
  11. Contract.Requires(key != null);
  12. Contract.Requires(keySize == key.Length << 3);
  13. _algorithm = algorithm;
  14. algorithm.Key = key;
  15. }
  16. public int DigestLength
  17. {
  18. get { return _algorithm.HashSize >> 3; }
  19. }
  20. public byte[] ComputeHash(byte[] input)
  21. {
  22. Contract.Requires(input != null);
  23. return _algorithm.ComputeHash(input);
  24. }
  25. }
  26. }