[CryptoAPI] [CryptoAPI] Using PEM keys on RSA methods

Forge Component
Published on 3 Mar by Ricardo Silva
22 votes
Published on 3 Mar by Ricardo Silva


As it stands the CryptoAPI uses the XML RSA Key format for its input parameters, is there any way to make it work with a PEM RSA key?

In my scenario the private key generated outside and is given to me in PEM RSA format and I'd still like to use this component to do the server side encryption/decryption.



.NET doesn't really have a built-in library which support PEM (that I found while I was implementing CryptoAPI).

As I was trying to add as little code of my own / third parties as possible, I decided to not drop in any converter using other libraries.

Since the only thing that changes is the format that the key is stored, you should be able to convert the PEM file into a XML key.

There's a converter online I found pretty quickly, but, for what I think should be pretty obvious reasons, I do not recommend sending your private key to any online utility. Fortunately, whoever built that converter also shared the code for it, which you should be able to use to convert the pem file to xml.

Let me know if you are having trouble with this, I might be able to dedicate some time to help you out on my spare time or over the weekend.

I found that converter also, and the converstion works fine for the keys I'm being provided and they also work fine with CryptoAPI, so I just need to go about creating the extension.

If it was natively supported I would just avoid the extra effort.