diff --git a/README.md b/README.md index 5708d0af4..9d3976cbf 100644 --- a/README.md +++ b/README.md @@ -143,33 +143,17 @@ using (var client = new SftpClient(connectionInfo)) Establish a SSH connection using user name and password, and reject the connection if the fingerprint of the server does not match the expected fingerprint: ```cs -byte[] expectedFingerPrint = new byte[] { - 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, - 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b - }; +using System.Linq; +using Renci.SshNet; -using (var client = new SshClient("sftp.foo.com", "guest", "pwd")) -{ - client.HostKeyReceived += (sender, e) => - { - if (expectedFingerPrint.Length == e.FingerPrint.Length) - { - for (var i = 0; i < expectedFingerPrint.Length; i++) - { - if (expectedFingerPrint[i] != e.FingerPrint[i]) - { - e.CanTrust = false; - break; - } - } - } - else - { - e.CanTrust = false; - } - }; - client.Connect(); -} +byte[] expectedFingerPrint = { + 0x66, 0x31, 0xaf, 0x00, 0x54, 0xb9, 0x87, 0x31, + 0xff, 0x58, 0x1c, 0x31, 0xb1, 0xa2, 0x4c, 0x6b +}; + +using var client = new SshClient("sftp.foo.com", "guest", "pwd"); +client.HostKeyReceived += (_, e) => e.CanTrust = expectedFingerPrint.SequenceEqual(e.FingerPrint); +client.Connect(); ``` ## Supporting SSH.NET