using System; using Renci.SshNet.Abstractions; using Renci.SshNet.Security; namespace Renci.SshNet.Common { /// /// Provides data for the HostKeyReceived event. /// public class HostKeyEventArgs : EventArgs { /// /// Gets or sets a value indicating whether host key can be trusted. /// /// /// true if host key can be trusted; otherwise, false. /// public bool CanTrust { get; set; } /// /// Gets the host key. /// public byte[] HostKey { get; private set; } /// /// Gets the host key name. /// public string HostKeyName{ get; private set; } /// /// Gets the MD5 fingerprint. /// /// /// MD5 fingerprint as byte array. /// public byte[] FingerPrint { get; private set; } /// /// Gets the SHA256 fingerprint. /// /// /// Base64 encoded SHA256 fingerprint with padding (equals sign) removed. /// public string FingerPrintSHA256 { get; private set; } /// /// Gets the length of the key in bits. /// /// /// The length of the key in bits. /// public int KeyLength { get; private set; } /// /// Initializes a new instance of the class. /// /// The host. public HostKeyEventArgs(KeyHostAlgorithm host) { CanTrust = true; HostKey = host.Data; HostKeyName = host.Name; KeyLength = host.Key.KeyLength; using (var md5 = CryptoAbstraction.CreateMD5()) { FingerPrint = md5.ComputeHash(host.Data); } using (var sha256 = CryptoAbstraction.CreateSHA256()) { FingerPrintSHA256 = Convert.ToBase64String(sha256.ComputeHash(host.Data)).Replace("=", ""); } } } }