Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generate a 2048 key with custom exponent size?

Is there a way to generate a 2048 RSA key pair, using RSACryptoServiceProvider with a custom defined exponent?

new RSACryptoServiceProvider(2048); // = 65537 always

For example, I want to set the exponent to 65535, but the hard-coded value seems to be 65537.

I've looked around, but was unable to find any information.

I am trying to generate a new key pair, not import an existing key, using RSACryptoServiceProvider.

I know that importing an already existent key, I can define modulus, exponent and other factors.

If its not possible, what alternatives do I have?

like image 812
Guapo Avatar asked Nov 08 '22 16:11

Guapo


1 Answers

You may use Bouncy Castle cryptographic library. Use RsaKeyPairGenerator class for key generating with RsaKeyGenerationParameters for setting of your public RSA exponent. See here the example with key pair generating. But pay attention with the choice of the exponent. The public RSA exponent should be a Fermat Number. See question Impacts of not using RSA exponent of 65537 for more details about choosing of the exponent.

See also useful posts about certificate generating Using Bouncy Castle from .NET. For your convenience you may generate Bouncy Castle certificate and convert it to .NET X509Certificate2 object.

Update:

I think the example in this question with using RSACryptoServiceProvider may help you.

like image 97
Didgeridoo Avatar answered Nov 15 '22 12:11

Didgeridoo