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

折月煮酒 提交于 2019-12-04 10:29:36

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!

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