How to generate SSH 2 RSA key in C# application?

霸气de小男生 提交于 2019-12-09 18:32:16

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!