1

I'm using C# and I'm trying to sign a string with a key produced from the PuTTY Key Generator. I'm not quite sure what I'm doing because I can't see how to import a key into the RsaEngine

I looked at the following:

AsymmetricKeyParameter key = new RsaKeyParameters(false, ???, ???);
RsaEngine rsa = new RsaEngine();
rsa.Init(true, key);

but it seems that RsaKeyParameter and AsymmetricKeyParameter take a modulus and a exponent which I don't know how to get from my already generated key? I could be using the wrong class though so if anyone has any pointers on this that would be excellent

I looked at: RSA signing and verification with C#,BouncyCastle and imported RSA key - Working Python example and non-working C# code sample inside but answer has a non existent function:

ConvertToRSAPrivateKey
Community
  • 1
  • 1
Jamie H
  • 590
  • 8
  • 29
  • Always specify some tags with a higher amount of followers, otherwise your question will fly "under the radar". – Maarten Bodewes Aug 03 '14 at 15:24
  • @JamieH, have you tried looking at RSACryptoServiceProvider (http://msdn.microsoft.com/en-us/library/system.security.cryptography.rsacryptoserviceprovider.signdata(v=vs.110).aspx)? RsaEngine in BC looks way too low level for the generic 'i need to sign data' requirement. – zaitsman Aug 03 '14 at 15:31

1 Answers1

0

You can first convert the PuttyGen keys into OpenSSH compatible keys and then convert this well documented format to C#.

The best I can come up with is this class of the SSH.NET library code.

In the mean time, please note that you are better off generating the key in the actual library that you want to use. Key formats, especially private key formats, are not always compatible.

Community
  • 1
  • 1
Maarten Bodewes
  • 80,169
  • 13
  • 121
  • 225