Export (0) Print
Expand All

CspKeyContainerInfo.KeyNumber Property

Gets a value that describes whether an asymmetric key was created as a signature key or an exchange key.

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

'Declaration
Public ReadOnly Property KeyNumber As KeyNumber
'Usage
Dim instance As CspKeyContainerInfo 
Dim value As KeyNumber 

value = instance.KeyNumber

Property Value

Type: System.Security.Cryptography.KeyNumber
One of the KeyNumber values that describes whether an asymmetric key was created as a signature key or an exchange key.

The value of the KeyNumber property is derived from the KeyNumber field of the CspParameters object that was used to initialize the CspKeyContainerInfo object.

An exchange key is an asymmetric key pair used to encrypt session keys so that they can be safely stored and exchanged with other users. The Exchange value specifies an exchange key. This value corresponds to the AT_KEYEXCHANGE value used in the unmanaged Microsoft Cryptographic API (CAPI).

A signature key is an asymmetric key pair used for authenticating (digitally signed) messages or files. The Signature value specifies a signature key. This value corresponds to the AT_SIGNATURE value used in CAPI.

The following code example creates a key container and retrieves information about that container.

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

Module CspKeyContainerInfoExample

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

        Try 
            ' 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()

            Console.WriteLine("CspKeyContainerInfo information:")

            Console.WriteLine()

            ' 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
            Console.WriteLine(e.ToString())
        Finally 
            ' Clear the key.
            rsa.Clear()
        End Try
        Console.ReadLine()

    End Sub 
End Module

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

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0

.NET Compact Framework

Supported in: 3.5, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft