3

I have a file testpublic.snk which holds a public key. I have created it with sn -p c:\test.snk c:\testpublic.snk. Now, how can I convert testpublic.snk to a string like

<RSAKeyValue><Modulus>z140GwiEJvuGOVqMQUxnojILR8rn2SFOViigoloku59H5eqzqca3Hdyl/jc+Acdb5ktzhBOOyGFElE0/Btlvw9cXVVW8zcT0MBOCaq25D1rSVYLGGM6nXzBrl1XsrBEadZbCgkcF5rw8GaYcYakijaltP1/hvxhbMOARM9VCQ50=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>

Thanks for your help.

poupou
  • 43,413
  • 6
  • 77
  • 174
BennoDual
  • 5,865
  • 15
  • 67
  • 153
  • I don't know about snk.exe but I think the RsaCryptoProvider has some ways to get the (public) as XML. – H H Sep 24 '11 at 13:42

1 Answers1

2

Simply re-use the (MIT.X11 licensed) code from Mono.Security StrongName class, available in github, then call ToXmlString on it's RSA property. Something like:

Console.WriteLine (new StrongName (data).RSA.ToXmlString (false));

Where data is a byte[] containing the content of your snk file. Also you can use true if you want the private key in your XML (it will work if it was available fom your snk file).

poupou
  • 43,413
  • 6
  • 77
  • 174