diff --git a/src/Renci.SshNet/Common/HostKeyEventArgs.cs b/src/Renci.SshNet/Common/HostKeyEventArgs.cs index 017b1e513..6100fdb7b 100644 --- a/src/Renci.SshNet/Common/HostKeyEventArgs.cs +++ b/src/Renci.SshNet/Common/HostKeyEventArgs.cs @@ -1,4 +1,6 @@ using System; +using System.Globalization; +using System.Linq; using Renci.SshNet.Abstractions; using Renci.SshNet.Security; @@ -28,10 +30,24 @@ public class HostKeyEventArgs : EventArgs public string HostKeyName{ get; private set; } /// - /// Gets the finger print. + /// Gets the MD5 fingerprint of the host key. /// public byte[] FingerPrint { get; private set; } + /// + /// Gets the MD5 fingerprint of the host key in the same format as the ssh command, + /// i.e. hexadecimal bytes seperated by colons, but without the MD5: prefix. + /// + /// 97:70:33:82:fd:29:3a:73:39:af:6a:07:ad:f8:80:49 + public string MD5FingerPrint { get; private set; } + + /// + /// Gets the SHA256 fingerprint of the host key in the same format as the ssh command, + /// i.e. non-padded base64, but without the SHA256: prefix. + /// + /// ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og + public string SHA256FingerPrint { get; private set; } + /// /// Gets the length of the key in bits. /// @@ -54,6 +70,11 @@ public HostKeyEventArgs(KeyHostAlgorithm host) using (var md5 = CryptoAbstraction.CreateMD5()) { FingerPrint = md5.ComputeHash(host.Data); + MD5FingerPrint = string.Join(":", FingerPrint.Select(e => e.ToString("x2", NumberFormatInfo.InvariantInfo))); + } + using (var sha256 = CryptoAbstraction.CreateSHA256()) + { + SHA256FingerPrint = Convert.ToBase64String(sha256.ComputeHash(host.Data)).TrimEnd('='); } } }