R – How to generate an RSA public/private key in .Net, of a specific length


I'm using the RSACryptoServiceProvider to do some asymmetric encryption.

As per MSDN, when you instantiate a new RSACryptoServiceProvider, you get a public/private key pair generated for you that you can use.

Clearly this pair is being generated using some defaults – specifically the length. I'd like to specify my own length for greater security.

How can I do this?

Thanks in advance.

Best Solution

One of the constructors for RSACryptoServiceProvider takes a KeySize as parameter. Do consult the docs about allowable values though.

Related Question