HMacMD5.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using System.Security.Cryptography;
  4. namespace Renci.SshNet.Security
  5. {
  6. /// <summary>
  7. /// Represents MD5 implementation of hashing algorithm
  8. /// </summary>
  9. public class HMacMD5 : HMac
  10. {
  11. private KeyedHashAlgorithm _hash;
  12. /// <summary>
  13. /// Instance of initialized hash algorithm that being used
  14. /// </summary>
  15. protected override KeyedHashAlgorithm Hash
  16. {
  17. get { return this._hash; }
  18. }
  19. /// <summary>
  20. /// Gets algorithm name.
  21. /// </summary>
  22. public override string Name
  23. {
  24. get { return "hmac-md5"; }
  25. }
  26. /// <summary>
  27. /// Initializes algorithm with specified key.
  28. /// </summary>
  29. /// <param name="key">The hash key.</param>
  30. public override void Init(IEnumerable<byte> key)
  31. {
  32. this._hash = new Renci.SshNet.Security.Cryptography.HMAC<Renci.SshNet.Security.Cryptography.MD5Hash>(key.Take(16).ToArray());
  33. }
  34. /// <summary>
  35. /// Releases unmanaged and - optionally - managed resources
  36. /// </summary>
  37. /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged ResourceMessages.</param>
  38. protected override void Dispose(bool disposing)
  39. {
  40. // Dispose managed ResourceMessages.
  41. if (this._hash != null)
  42. {
  43. this._hash.Dispose();
  44. this._hash = null;
  45. }
  46. base.Dispose(disposing);
  47. }
  48. }
  49. }