<PackageReference Include="SSH.NET" Version="2023.0.1" />

HostKeyEventArgs

public class HostKeyEventArgs : EventArgs
Provides data for the HostKeyReceived event.
using Renci.SshNet.Abstractions; using Renci.SshNet.Security; using System; using System.Security.Cryptography; namespace Renci.SshNet.Common { public class HostKeyEventArgs : EventArgs { private readonly Lazy<byte[]> _lazyFingerPrint; private readonly Lazy<string> _lazyFingerPrintSHA256; private readonly Lazy<string> _lazyFingerPrintMD5; public bool CanTrust { get; set; } public byte[] HostKey { get; set; } public string HostKeyName { get; set; } public byte[] FingerPrint => _lazyFingerPrint.Value; public string FingerPrintSHA256 => _lazyFingerPrintSHA256.Value; public string FingerPrintMD5 => _lazyFingerPrintMD5.Value; public int KeyLength { get; set; } public HostKeyEventArgs(KeyHostAlgorithm host) { if (host == null) throw new ArgumentNullException("host"); CanTrust = true; HostKey = host.Data; HostKeyName = host.Name; KeyLength = host.Key.KeyLength; _lazyFingerPrint = new Lazy<byte[]>(delegate { using (MD5 mD = CryptoAbstraction.CreateMD5()) return mD.ComputeHash(HostKey); }); _lazyFingerPrintSHA256 = new Lazy<string>(delegate { using (SHA256 sHA = CryptoAbstraction.CreateSHA256()) return Convert.ToBase64String(sHA.ComputeHash(HostKey)).Replace("=", string.Empty); }); _lazyFingerPrintMD5 = new Lazy<string>(() => BitConverter.ToString(FingerPrint).Replace('-', ':').ToLowerInvariant()); } } }