简体   繁体   中英

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.

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.

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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