This documentation is archived and is not being maintained.

RSACryptoServiceProvider.CspKeyContainerInfo Property

Note: This property is new in the .NET Framework version 2.0.

Gets a CspKeyContainerInfo object that describes additional information about a cryptographic key pair.

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

<ComVisibleAttribute(False)> _
Public ReadOnly Property CspKeyContainerInfo As CspKeyContainerInfo
Dim instance As RSACryptoServiceProvider
Dim value As CspKeyContainerInfo

value = instance.CspKeyContainerInfo

/** @property */
public final CspKeyContainerInfo get_CspKeyContainerInfo ()

public final function get CspKeyContainerInfo () : CspKeyContainerInfo

Property Value

A CspKeyContainerInfo object that describes additional information about a cryptographic key pair.

Use the CspKeyContainerInfo property to retrieve additional information about a cryptographic key pair. The returned CspKeyContainerInfo object describes whether the key is exportable, and specifies the key container name, information about the provider, and other information.

In cases where a random key is generated, a key container will not be created until you call a method that uses the key. Some properties of the CspKeyContainerInfo object returned by the CspKeyContainerInfo property will throw a CryptographicException if a key container has not been created. To make sure that a key container has been created, call a method such as Encrypt, Decrypt, SignData, SignHash, and so on, before you call the CspKeyContainerInfo property.

The following code example demonstrates how to call the CspKeyContainerInfo property.

Imports System
Imports System.Security.Cryptography
Imports System.Text

Module CspKeyContainerInfoExample

    Sub Main(ByVal args() As String)
        Dim rsa As New RSACryptoServiceProvider()

            ' Note: In cases where a random key is generated,   
            ' a key container is not created until you call  
            ' a method that uses the key.  This example calls
            ' the Encrypt method before calling the
            ' CspKeyContainerInfo property so that a key
            ' container is created.  
            ' Create some data to encrypt and display it.
            Dim data As String = "Here is some data to encrypt."

            Console.WriteLine("Data to encrypt: " + data)

            ' Convert the data to an array of bytes and 
            ' encrypt it.
            Dim byteData As Byte() = Encoding.ASCII.GetBytes(data)

            Dim encData As Byte() = rsa.Encrypt(byteData, False)

            ' Display the encrypted value.
            Console.WriteLine("Encrypted Data: " + Encoding.ASCII.GetString(encData))


            Console.WriteLine("CspKeyContainerInfo information:")


            ' Create a new CspKeyContainerInfo object.
            Dim keyInfo As CspKeyContainerInfo = rsa.CspKeyContainerInfo

            ' Display the value of each property.
            Console.WriteLine("Accessible property: " + keyInfo.Accessible.ToString())

            Console.WriteLine("Exportable property: " + keyInfo.Exportable.ToString())

            Console.WriteLine("HardwareDevice property: " + keyInfo.HardwareDevice.ToString())

            Console.WriteLine("KeyContainerName property: " + keyInfo.KeyContainerName)

            Console.WriteLine("KeyNumber property: " + keyInfo.KeyNumber.ToString())

            Console.WriteLine("MachineKeyStore property: " + keyInfo.MachineKeyStore.ToString())

            Console.WriteLine("Protected property: " + keyInfo.Protected.ToString())

            Console.WriteLine("ProviderName property: " + keyInfo.ProviderName)

            Console.WriteLine("ProviderType property: " + keyInfo.ProviderType.ToString())

            Console.WriteLine("RandomlyGenerated property: " + keyInfo.RandomlyGenerated.ToString())

            Console.WriteLine("Removable property: " + keyInfo.Removable.ToString())

            Console.WriteLine("UniqueKeyContainerName property: " + keyInfo.UniqueKeyContainerName)

        Catch e As Exception
            ' Clear the key.
        End Try

    End Sub
End Module

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.

.NET Framework

Supported in: 2.0

.NET Compact Framework

Supported in: 2.0