Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/Renci.SshNet/Common/HostKeyEventArgs.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using System.Globalization;
using System.Linq;
using Renci.SshNet.Abstractions;
using Renci.SshNet.Security;

Expand Down Expand Up @@ -28,10 +30,24 @@ public class HostKeyEventArgs : EventArgs
public string HostKeyName{ get; private set; }

/// <summary>
/// Gets the finger print.
/// Gets the MD5 fingerprint of the host key.
/// </summary>
public byte[] FingerPrint { get; private set; }

/// <summary>
/// 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 <c>MD5:</c> prefix.
/// </summary>
/// <example><c>97:70:33:82:fd:29:3a:73:39:af:6a:07:ad:f8:80:49</c></example>
public string MD5FingerPrint { get; private set; }

/// <summary>
/// Gets the SHA256 fingerprint of the host key in the same format as the ssh command,
/// i.e. non-padded base64, but without the <c>SHA256:</c> prefix.
/// </summary>
/// <example><c>ohD8VZEXGWo6Ez8GSEJQ9WpafgLFsOfLOtGGQCQo6Og</c></example>
public string SHA256FingerPrint { get; private set; }

/// <summary>
/// Gets the length of the key in bits.
/// </summary>
Expand All @@ -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('=');
}
}
}
Expand Down