Export (0) Print
Expand All

RSACryptoServiceProvider.ImportParameters Method

Imports the specified RSAParameters.

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

public override void ImportParameters (
	RSAParameters parameters
)
public void ImportParameters (
	RSAParameters parameters
)
public override function ImportParameters (
	parameters : RSAParameters
)
Not applicable.

Parameters

parameters

The parameters for RSA.

Exception typeCondition

CryptographicException

The cryptographic service provider (CSP) cannot be acquired.

-or-

The parameters parameter has missing fields.

The following code example imports key information created from an RSAParameters object into an RSACryptoServiceProvider object.

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);

}

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.get_Message());
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft