This documentation is archived and is not being maintained.

RSACryptoServiceProvider Constructor (Int32, CspParameters)

Initializes a new instance of the RSACryptoServiceProvider class with the specified key size and parameters.

Namespace:  System.Security.Cryptography
Assembly:  mscorlib (in mscorlib.dll)

new : 
        dwKeySize:int * 
        parameters:CspParameters -> RSACryptoServiceProvider


Type: System.Int32
The size of the key to use in bits.
Type: System.Security.Cryptography.CspParameters
The parameters to be passed to the cryptographic service provider (CSP).


The CSP cannot be acquired.


The key cannot be created.

This constructor creates or reuses a key container specified using the KeyContainerName field of the parameters parameter.

By default, this constructor creates an Exchange key pair suitable to encrypt session keys so that they can be safely stored and exchanged with other users. The generated key corresponds to a key generated using the AT_KEYEXCHANGE value used in the unmanaged Microsoft Cryptographic API (CAPI).

You can create a Signature key pair suitable for authenticating (digitally signed) messages or files by setting the KeyNumber field of the parameters parameter to the Signature value. This type of key corresponds to the AT_SIGNATURE value used in CAPI.

If you create an RSACryptoServiceProvider object with the Exchange value specified and then create another RSACryptoServiceProvider object with the Signature value specified, both keys will be placed in a single container if both objects specify the same key container name.

To create a key that is compatible with stong-name signing using the RSACryptoServiceProvider class, you must create a Signature key pair.

The following code example creates a RSACryptoServiceProvider, generates a new key, and stores it in a key container.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.