RSACryptoServiceProvider.ImportParameters Method (RSAParameters)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Imports the specified RSAParameters.

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

Public Overrides Sub ImportParameters (
	parameters As RSAParameters
)

Parameters

parameters
Type: System.Security.Cryptography.RSAParameters

The parameters for RSA.

Exception Condition
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. 
    Using 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.
        Using RSA2 As New RSACryptoServiceProvider()

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

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

KeyContainerPermissionAccessEntryCollection

for permission to import a key. Security action: Demand. Associated enumeration: KeyContainerPermissionFlags.Import

.NET Framework
Available since 1.1
Windows Phone Silverlight
Available since 7.1
Return to top
Show: