Creating KeyPair using wodsftp.net - WeOnlyDo Discussion board

Creating KeyPair using wodsftp.net (wodSFTP / wodSFTP.NET / wodSFTPdll)

by hit_arc, Wednesday, June 04, 2008, 10:50 (5814 days ago)

Hi,

I am using your wodsftp component. I need to generate key pair for connecting to a server.

I am using the following code

String Filename = c:\Keys\secretkey.rsa ;
String Password = secret_password ;
KeyManager km = new KeyManager();
try
{
km.Load(Filename, Password);
}
catch (Exception)
{
km.Generate(SSHKeyTypes.RSAKey);
km.Save(SSHKeyTypes.RSAKey, Filename, Password);
}

But how do i generate public key thorugh this code as i am able to generate and save only private key in this code.

Regards
hit_arc

Re: Creating KeyPair using wodsftp.net

by wodDamir, Wednesday, June 04, 2008, 11:10 (5814 days ago) @ hit_arc

Hi hit_arc,

Public key is generated when Generate method is used. You should just export the PublicKeyOpenSSH property to a file, and you're done.

Something like this:

[code]string publicKey = KM.PublicKeyOpenSSH(WeOnlyDo.Security.Cryptography.SSHKeyTypes.RSAKey);
System.IO.File.WriteAllText(@ C:publickey.txt , publicKey);[/code]

Can you try something like that?

Regards,
Damba

Re: Creating KeyPair using wodsftp.net

by hit_arc, Wednesday, June 04, 2008, 11:54 (5814 days ago) @ wodDamir

Hi Damba,

Thanks for replying, well i need the public key to be sent to the people who are monitoring the server. So that i can access that server through the private key authentication. Will the key generated from above method will work in that senerio as it will just save the content of public key in that particular file.

Regards
hit_arc

Re: Creating KeyPair using wodsftp.net

by wodDamir, Wednesday, June 04, 2008, 12:02 (5814 days ago) @ hit_arc

hit_arc,

Yes, ofcourse. When you call the Generate method, both public and his appropriate private key are generated. I showed you how to export Public key in OpenSSH format, since that's the most widely used.

The public key exported this way and copied to the server should work with appropriate PrivateKey (exported with Save method).

You can also try using our free application from here: http://www.weonlydo.com/Samples/KeyManager.NET.zip

This application uses our wodKeyManager.dll for generating, exporting, etc.

Hope I helped.

Regards,
Damba