I am trying to connect up to a WinSCP server using the WinSCP .NET assembly. The problem I am having is that it bombs checking the host key fingerprint. I have created a RSA key. My code is as follows:
var server = new WinSCP.SessionOptions();
server.UserName = "ftp_user";
server.Password = "******";
server.HostName = "192.x.x.x";
server.Protocol = WinSCP.Protocol.Sftp;
server.SshHostKeyFingerprint =
"9f:39:52:d5:08:0c:1d:a8:02:c9:7e:44:49:7f:44:fb";
var session = new WinSCP.Session();
session.Open(server);
At the SshHostKeyFingerprint property assignment I get the following error:
SSH host key fingerprint "9f:39:52:d5:08:0c:1d:a8:02:c9:7e:44:49:7f:44:fb" does not match pattern /(ssh-rsa |ssh-dss )?\d+ ([0-9a-f]{2}:){15}[0-9a-f]{2}(;(ssh-rsa |ssh-dss )?\d+ ([0-9a-f]{2}:){15}[0-9a-f]{2})*/
If I am reading this right it is checking for 15 2 character sets, and I am assigning a 16 set value. I got this value from the server.
UPDATE:
What I was missing was the fingerprint type (ssh-dss or ssh-rsa) and its size (1024, 2048 etc.). Therefore, the answer is as follows:
server.SshHostKeyFingerprint =
"ssh-rsa 1024 9f:39:52:d5:08:0c:1d:a8:02:c9:7e:44:49:7f:44:fb";
If I am reading the regular expression correctly it does not give you any idea that you need the fingerprint size after the fingerprint type.
I hope this helps someone else. Thanks everyone for your insight and input.

This looks for 15 pairs of hex digits with a colon after each pair, then one more pair that doesn't have a colon. So it's not 15/16 that is your problem. It's the rest of it.
There are a bunch of optional components, but the mandatory component you're missing is the
\d+before the hex. It's a decimal number, apparently representing the key size, which will probably be something like 1024 or 2048 or 4096. Put it first, then a space, then your hex stuff.