简体   繁体   English

如何在.Net中生成特定长度的RSA公钥/私钥?

[英]How do I generate an RSA public/private key in .Net, of a specific length?

I'm using the RSACryptoServiceProvider to do some asymmetric encryption. 我正在使用RSACryptoServiceProvider进行一些非对称加密。

As per MSDN, when you instantiate a new RSACryptoServiceProvider, you get a public/private key pair generated for you that you can use. 根据MSDN,当实例化一个新的RSACryptoServiceProvider时,将为您生成一个可以使用的公用/专用密钥对。

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. 提前致谢。

One of the constructors for RSACryptoServiceProvider takes a KeySize as parameter. RSACryptoServiceProvider的构造函数之一采用KeySize作为参数。 Do consult the docs about allowable values though. 不过,请务必参考有关允许值的文档。

http://msdn.microsoft.com/en-us/library/d0c0sch1.aspx http://msdn.microsoft.com/en-us/library/d0c0sch1.aspx

public:
RSACryptoServiceProvider(
    int dwKeySize, // <- wow a size!
    CspParameters^ parameters
)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM