HostKeyEventArgs.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using Renci.SshNet.Security.Cryptography;
  6. namespace Renci.SshNet.Common
  7. {
  8. /// <summary>
  9. /// Provides data for the HostKeyReceived event.
  10. /// </summary>
  11. public class HostKeyEventArgs : EventArgs
  12. {
  13. /// <summary>
  14. /// Gets or sets a value indicating whether host key can be trusted.
  15. /// </summary>
  16. /// <value>
  17. /// <c>true</c> if host key can be trusted; otherwise, <c>false</c>.
  18. /// </value>
  19. public bool CanTrust { get; set; }
  20. /// <summary>
  21. /// Gets the host key.
  22. /// </summary>
  23. public byte[] HostKey { get; private set; }
  24. /// <summary>
  25. /// Gets the finger print.
  26. /// </summary>
  27. public byte[] FingerPrint { get; private set; }
  28. /// <summary>
  29. /// Initializes a new instance of the <see cref="HostKeyEventArgs"/> class.
  30. /// </summary>
  31. /// <param name="hostKey">The host key.</param>
  32. public HostKeyEventArgs(byte[] hostKey)
  33. {
  34. this.CanTrust = true; // Set default value
  35. this.HostKey = hostKey;
  36. using (var md5 = new MD5Hash())
  37. {
  38. this.FingerPrint = md5.ComputeHash(hostKey);
  39. }
  40. }
  41. }
  42. }