5

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?

Guapo
  • 3,446
  • 9
  • 36
  • 63
  • 1
    NIST requires 65537: http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-78-4.pdf Good backgrounder [is here](https://crypto.stackexchange.com/a/3113) – Hans Passant Oct 04 '17 at 13:34
  • @HansPassant I am porting a client/server from c++ to c# and the client currently only uses 65535, to receive the public key which I am unsure at which point all clients variations will be updated. – Guapo Oct 04 '17 at 13:57
  • Well, ImportParameters() is the key. Note that the code in the answer might be helping too much with Reverse(). – Hans Passant Oct 04 '17 at 14:31
  • @HansPassant sorry. I don't get it, wouldn't change the exponent of an already generated keypair simple kill it? – Guapo Oct 05 '17 at 06:30

1 Answers1

1

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.

Didgeridoo
  • 1,222
  • 2
  • 14
  • 21