Using BouncyCastle to augment the .NET RSACryptoServiceProvider class

Rory Braybrook
The new control plane
1 min readJul 30, 2018

Continuing my detour into cryptography …

While the RSACryptoServiceProvider class allows SHA512 signing, it does not allow SHA512 encryption / decryption.

The BouncyCastle (BC) library does. The issue is how to convert a RSACryptoServiceProvider key to a BC one. The main issue is that the RSACryptoServiceProvider libraries favour byte arrays whereas the BC ones don’t.

Took me a while to figure out how to do the conversion.

The key is to use RSAParameters as the bridge between the two.

The code:

Gist.

Note that the signing can be handled completely within the .NET library whereas the encryption switches over to the BC library.

Enjoy!

--

--

Rory Braybrook
The new control plane

NZ Microsoft Identity dude and MVP. Azure AD/B2C/ADFS/Auth0/identityserver. StackOverflow: https://bit.ly/2XU4yvJ Presentations: http://bit.ly/334ZPt5