This documentation is archived and is not being maintained.

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)

property KeyNumber KeyNumber {
	KeyNumber get ();

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.

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Text;
int main()
   RSACryptoServiceProvider^ rsa = gcnew 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.
      String^ data = L"Here is some data to encrypt.";
      Console::WriteLine( L"Data to encrypt: {0}", data );

      // Convert the data to an array of bytes and  
      // encrypt it. 
      array<Byte>^byteData = Encoding::ASCII->GetBytes( data );
      array<Byte>^encData = rsa->Encrypt( byteData, false );

      // Display the encrypted value.
      Console::WriteLine( L"Encrypted Data: {0}", Encoding::ASCII->GetString( encData ) );
      Console::WriteLine( L"CspKeyContainerInfo information:" );

      // Create a new CspKeyContainerInfo object.
      CspKeyContainerInfo^ keyInfo = rsa->CspKeyContainerInfo;

      // Display the value of each property.
      Console::WriteLine( L"Accessible property: {0}", keyInfo->Accessible );
      Console::WriteLine( L"Exportable property: {0}", keyInfo->Exportable );
      Console::WriteLine( L"HardwareDevice property: {0}", keyInfo->HardwareDevice );
      Console::WriteLine( L"KeyContainerName property: {0}", keyInfo->KeyContainerName );
      Console::WriteLine( L"KeyNumber property: {0}", keyInfo->KeyNumber );
      Console::WriteLine( L"MachineKeyStore property: {0}", keyInfo->MachineKeyStore );
      Console::WriteLine( L"Protected property: {0}", keyInfo->Protected );
      Console::WriteLine( L"ProviderName property: {0}", keyInfo->ProviderName );
      Console::WriteLine( L"ProviderType property: {0}", keyInfo->ProviderType );
      Console::WriteLine( L"RandomlyGenerated property: {0}", keyInfo->RandomlyGenerated );
      Console::WriteLine( L"Removable property: {0}", keyInfo->Removable );
      Console::WriteLine( L"UniqueKeyContainerName property: {0}", keyInfo->UniqueKeyContainerName );
   catch ( Exception^ e ) 
      Console::WriteLine( e );

      // Clear the key.


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