SSH library with passphrase rsa secret key support

I am currently working on a small Visual C # application in which I need the SSH library. I have already tried DotNetSSH, Renci.SshNet and SharpSsh. The Granados SSH library is poorly documented (at least I found almost nothing), so I skipped this.

All these libraries have one huge problem (IMHO): they cannot open SSH private keys with a passphrase.

Renci.SshNet does not support AES. DotNetSSH and SharpSsh use jsch (java ssh library) as the base, and there seems to be an error (?), So it does not block the private key and continues to request a passphrase.

Connecting with a username + password and private keys without a passphrase works fine with SharpSsh.

Has anyone already had the same problem? Or is there another C # SSH library with support for "RSA privatekey and passphrase"?

thanks in advance

+4
source share
3 answers

I have successfully used the open source SSH.NET library to work with SSH and SFTP.

This is the code to connect with keyfile + passphrase.

public void Connect(string host, int port, string user, string passPhrase, string privateKeyFilePath) { var keyFiles = new[] { new PrivateKeyFile(privateKeyFilePath, passPhrase) }; var methods = new List<AuthenticationMethod>(); methods.Add(new PasswordAuthenticationMethod(user, passPhrase)); methods.Add(new PrivateKeyAuthenticationMethod(user, keyFiles)); var con = new ConnectionInfo(host, port, user, methods.ToArray()); var client = new SshClient(con); client.Connect(); // create an xterm shell var Shell = client.CreateShellStream("xterm", 80, 24, 800, 600, 1024); // for reading & writing to the shell var reader = new StreamReader(Shell); var writer = new StreamWriter(Shell); // .... client.Disconnect(); } 

Private Key File Format

Please note that your private key file must be in OpenSSH format. If you open the key file in Notepad ++, it should have "BEGIN RSA PRIVATE KEY" on the first line.

If not, then convert your private key file to OpenSSH format using puttygen.

  • Open private key in puttygen
  • Go to the "Conversions" menu and select "Export OpenSSH Key."
  • Save this new key in a file and use it.
+3
source

Our SecureBlackbox downloads and saves SSH keys in all common formats and supports encrypted key files. Not sure if another library is doing this.

0
source

Perhaps the Chilkat SSH component will help you.

But it is not free.

0
source

Source: https://habr.com/ru/post/1432336/


All Articles