I'm building my own .NET Standard 2.0 library for DocuSign's API and I need to get an RSA
instance from the public and private key strings they generated so I can create the JWT. While I was prototyping this in LINQPad, I had the advantage of using the .NET 7 runtime and the RSA.ImportFromPem()
, but that's not available in .NET Standard 2.0.
I tried to come up with something using Bouncy Castle, but it's my first time using the library and I'm not well versed in cryptography.
How can I take a string input of the public or private key and get an RSA
instance to use later on for the JWT generation?
The library has to be .NET Standard 2.0 because the project that will be consuming it is on .NET Framework 4.8.
An example of the strings I'm working with:
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAwvyMB2MwWJ1TG2iTbozZOovSAEeUBg6dpqz+pGhwf0ll3OU1
...
-----END RSA PRIVATE KEY-----
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAwvyMB2MwWJ1TG2iTbozZ
...
-----END PUBLIC KEY-----
I also don't want to deal with saving the strings to files, then to read them, then to delete them. The API docs state that the JWT has to be regenerated every 45 minutes, and I'd rather just hold the strings in memory and use them as needed.