Generate a 2048 key with custom exponent size?

你离开我真会死。 提交于 2021-01-27 05:40:20

问题


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?


回答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.



来源:https://stackoverflow.com/questions/46508225/generate-a-2048-key-with-custom-exponent-size

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!