HostKeyEventArgs.cs 1.8 KB

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