This documentation is archived and is not being maintained.

RSACryptoServiceProvider.ImportParameters Method

Imports the specified RSAParameters.

[Visual Basic]
Overrides Public Sub ImportParameters( _
   ByVal parameters As RSAParameters _
)
[C#]
public override void ImportParameters(
 RSAParameters parameters
);
[C++]
public: void ImportParameters(
 RSAParameters parameters
);
[JScript]
public override function ImportParameters(
   parameters : RSAParameters
);

Parameters

parameters
The parameters for RSA.

Exceptions

Exception Type Condition
CryptographicException The cryptographic service provider (CSP) cannot be acquired.

-or-

The parameters parameter has missing fields.

Example

[Visual Basic] 
Try
    'Create a new RSACryptoServiceProvider object. 
    Dim RSA As New RSACryptoServiceProvider()

    'Export the key information to an RSAParameters object.
    'Pass false to export the public key information or pass
    'true to export public and private key information.
    Dim RSAParams As RSAParameters = RSA.ExportParameters(False)

    'Create another RSACryptoServiceProvider object.
    Dim RSA2 As New RSACryptoServiceProvider()

    'Import the the key information from the other 
    'RSACryptoServiceProvider object.  
    RSA2.ImportParameters(RSAParams)


Catch e As CryptographicException
    'Catch this exception in case the encryption did
    'not succeed.
    Console.WriteLine(e.Message)
End Try

[C#] 
try
{
    //Create a new RSACryptoServiceProvider object. 
    RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

    //Export the key information to an RSAParameters object.
    //Pass false to export the public key information or pass
    //true to export public and private key information.
    RSAParameters RSAParams = RSA.ExportParameters(false);

    //Create another RSACryptoServiceProvider object.
    RSACryptoServiceProvider RSA2 = new RSACryptoServiceProvider();

    //Import the the key information from the other 
    //RSACryptoServiceProvider object.  
    RSA2.ImportParameters(RSAParams);


}
catch(CryptographicException e)
{
    //Catch this exception in case the encryption did
    //not succeed.
    Console.WriteLine(e.Message);

}

[C++] 
try {
    //Create a new RSACryptoServiceProvider object. 
    RSACryptoServiceProvider* RSA = new RSACryptoServiceProvider();

    //Export the key information to an RSAParameters object.
    //Pass false to export the public key information or pass
    //true to export public and private key information.
    RSAParameters RSAParams = RSA->ExportParameters(false);

    //Create another RSACryptoServiceProvider object.
    RSACryptoServiceProvider* RSA2 = new RSACryptoServiceProvider();

    //Import the the key information from the other 
    //RSACryptoServiceProvider object.  
    RSA2->ImportParameters(RSAParams);
} catch (CryptographicException* e) {
    //Catch this exception in case the encryption did
    //not succeed.
    Console::WriteLine(e->Message);
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

RSACryptoServiceProvider Class | RSACryptoServiceProvider Members | System.Security.Cryptography Namespace | Cryptographic Services

Show: