问题
I would like to write an application that will generate SSH 2 RSA public and private keys as well.
I would like to get the keys as format as the PuTTY Key Generator can generate.

With the help of ChilKat I can generate the public and private keys as well, but I don't know how to get that kind of format.
Is there any sample to get the keys at that format or I missed something?
Thank you very much!
回答1:
I found a solution: Download the Chilkat.NET Nuget from the Nuget Gallery. With the help of this library, you can generate an RSA Key Pair in the following way:
public ISshKeyPair RsaKeyPair()
{
Chilkat.SshKey key = new Chilkat.SshKey();
bool success;
int numBits;
int exponent;
numBits = 2048;
exponent = 65537;
success = key.GenerateRsaKey(numBits, exponent);
var sshKeyPair = new SshKeyPair();
sshKeyPair.PublicKey = key.ToOpenSshPublicKey();
sshKeyPair.PrivateKey = key.ToPuttyPrivateKey(false);
if (!success) RsaKeyPair();
return sshKeyPair;
}
Cheers!
来源:https://stackoverflow.com/questions/25020017/how-to-generate-ssh-2-rsa-key-in-c-sharp-application