SFTP: How to authenticate using private key which is not stored in file system?

0 votes
asked Dec 8, 2010 by Rebex KB (8,430 points)
edited Mar 30, 2011

I'd like to authenticate to an SFTP server using my private key. The private key is not stored in the filesystem.

1 Answer

0 votes
answered Dec 8, 2010 by Rebex KB (8,430 points)
edited Dec 8, 2010
Best answer

Following code shows how:

// create client and connect 
Sftp client = new Sftp();

// instead of loading it from a disk file, load the private key from a byte array
//SshPrivateKey privateKey = new SshPrivateKey("key_rsa.pem", "password");

byte[] privateKeyData = YourMethodForObtainingPrivateKey();    
SshPrivateKey privateKey = new SshPrivateKey(privateKeyData, "password");

// authenticate 
client.Login(username, privateKey);

// ...