RSACryptoServiceProvider.ImportParameters Method
.NET Framework 2.0
Imports the specified RSAParameters.
Namespace: System.Security.Cryptography
Assembly: mscorlib (in mscorlib.dll)
Assembly: mscorlib (in mscorlib.dll)
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());
}
- KeyContainerPermission for permission to import a key. Associated enumeration: Import. Security action: Demand.
Windows 98, Windows 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.