HostKeyEventArgs.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using Renci.SshNet.Security.Cryptography;
  3. using Renci.SshNet.Security;
  4. namespace Renci.SshNet.Common
  5. {
  6. /// <summary>
  7. /// Provides data for the HostKeyReceived event.
  8. /// </summary>
  9. public class HostKeyEventArgs : EventArgs
  10. {
  11. /// <summary>
  12. /// Gets or sets a value indicating whether host key can be trusted.
  13. /// </summary>
  14. /// <value>
  15. /// <c>true</c> if host key can be trusted; otherwise, <c>false</c>.
  16. /// </value>
  17. public bool CanTrust { get; set; }
  18. /// <summary>
  19. /// Gets the host key.
  20. /// </summary>
  21. public byte[] HostKey { get; private set; }
  22. /// <summary>
  23. /// Gets the host key name.
  24. /// </summary>
  25. public string HostKeyName{ get; private set; }
  26. /// <summary>
  27. /// Gets the finger print.
  28. /// </summary>
  29. public byte[] FingerPrint { get; private set; }
  30. /// <summary>
  31. /// Gets the length of the key in bits.
  32. /// </summary>
  33. /// <value>
  34. /// The length of the key in bits.
  35. /// </value>
  36. public int KeyLength { get; private set; }
  37. /// <summary>
  38. /// Initializes a new instance of the <see cref="HostKeyEventArgs"/> class.
  39. /// </summary>
  40. /// <param name="host">The host.</param>
  41. public HostKeyEventArgs(KeyHostAlgorithm host)
  42. {
  43. CanTrust = true; // Set default value
  44. HostKey = host.Data;
  45. HostKeyName = host.Name;
  46. KeyLength = host.Key.KeyLength;
  47. using (var md5 = HashAlgorithmFactory.CreateMD5())
  48. {
  49. FingerPrint = md5.ComputeHash(host.Data);
  50. }
  51. }
  52. }
  53. }