Authentication into SFTP server using PrivateKey - WeOnlyDo Discussion board

Authentication into SFTP server using PrivateKey (wodFtpDLX / wodFtpDLX.NET)

by jxt, Wednesday, April 01, 2015, 22:02 (3285 days ago)

Hello,

I am having a hard time supplying the Private Key via code, to authenticate into an SFTP server.

Here's my code -



WeOnlyDo.Client.FtpDLX ftp = new FtpDLX();

ftp.Hostname = "xxxxx";
ftp.Protocol = Protocols.SFTP;
ftp.Port = 22;

ftp.Login = "xxxxx";
ftp.Authentication = Authentications.PublicKey;
ftp.PrivateKey = "-----BEGIN RSA PRIVATE KEY-----MIIE.. ..Q1YSo=-----END RSA PRIVATE KEY-----";

ftp.Blocking = true;
ftp.Timeout = 10;

ftp.Connect();

I generated a SSH-2 RSA Public/Private key pair using puTTYgen and subsequently converted the Private Key to OpenSSH format and saved it to a file. How do I supply this Private key into the "PrivateKey" property? When I try to use the contents of the Private Key file as is - pasted as one long string -, I get the error "Failed to import Private Key".

Your help is much appreciated.

Authentication into SFTP server using PrivateKey

by Jasmine, Wednesday, April 01, 2015, 22:13 (3285 days ago) @ jxt
edited by Jasmine, Sunday, April 19, 2015, 13:51

Hi jxt.

You need to use different component (wodKeyManager, provided with wodFtpDLX.NET) to load your key from that format. Once loaded in wodKeyManager, you convert it to XML format, and then you can proceed without wodKeyManager in the future. Code would look like this:

dlx1 = New WeOnlyDo.Client.FtpDLX
key = New WeOnlyDo.Security.Cryptography.KeyManager

'do this only once, then you have format suitable for wodFtpDLX.NET
'key.Load("c:\RSAprivate.txt")
'TextBox1.Text = (key.ToXmlString(WeOnlyDo.Security.Cryptography.SSHKeyTypes.RSAKey, True))

dlx1.Protocol = WeOnlyDo.Client.Protocols.SFTP
dlx1.Hostname = "your_ip"
dlx1.Authentication = WeOnlyDo.Client.Authentications.PublicKey
dlx1.Login = "your_login"
dlx1.PrivateKey = "<RSAKeyValue><Modulus>...............</RSAKeyValue>"
dlx1.Blocking = True
dlx1.Connect()

Can you try that?

Warm regards,
Jasmine

Authentication into SFTP server using PrivateKey

by jxt, Thursday, April 02, 2015, 19:05 (3284 days ago) @ Jasmine

Jasmine,

Thank you very much. That worked for me. Appreciate your quick response.

Thanks,
Jay