CspKeyContainerInfo Klasa

Definicja

Zawiera dodatkowe informacje o parze kluczy kryptograficznych. Klasa ta nie może być dziedziczona.

public ref class CspKeyContainerInfo sealed
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public sealed class CspKeyContainerInfo
public sealed class CspKeyContainerInfo
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class CspKeyContainerInfo
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
type CspKeyContainerInfo = class
type CspKeyContainerInfo = class
[<System.Runtime.InteropServices.ComVisible(true)>]
type CspKeyContainerInfo = class
Public NotInheritable Class CspKeyContainerInfo
Dziedziczenie
CspKeyContainerInfo
Atrybuty

Przykłady

Poniższy przykład kodu tworzy kontener kluczy i pobiera informacje o tym kontenerze.

using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Text;
int main()
{
   RSACryptoServiceProvider^ rsa = gcnew 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.
      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();
      Console::WriteLine( L"CspKeyContainerInfo information:" );
      Console::WriteLine();
      
      // 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 );
   }
   finally
   {
      
      // Clear the key.
      rsa->Clear();
   }

}
using System;
using System.Security.Cryptography;
using System.Text;

public class CspKeyContainerInfoExample
{

    public static void Main(String[] args)
    {
        RSACryptoServiceProvider rsa = 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.
            string data = "Here is some data to encrypt.";

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

            // Convert the data to an array of bytes and
            // encrypt it.
            byte[] byteData = Encoding.ASCII.GetBytes(data);

            byte[] encData = 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.
            CspKeyContainerInfo keyInfo = rsa.CspKeyContainerInfo;

            // Display the value of each property.

            Console.WriteLine("Accessible property: " + keyInfo.Accessible);

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

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

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

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

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

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

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

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

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

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

            Console.WriteLine("UniqueKeyContainerName property: " + keyInfo.UniqueKeyContainerName);
        }
        catch (Exception e)
        {
            Console.WriteLine(e.ToString());
        }
        finally
        {
            // Clear the key.
            rsa.Clear();
        }
    }
}
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

Uwagi

Ta klasa służy do uzyskiwania dodatkowych informacji o parze kluczy, takich jak nazwa kontenera kluczy lub numer klucza.

W przypadkach, gdy losowy klucz jest generowany przez RSACryptoServiceProvider klasę lub DSACryptoServiceProvider, kontener kluczy nie zostanie utworzony do momentu wywołania metody używającej klucza. Niektóre właściwości CspKeyContainerInfo klasy spowodują CryptographicException zgłoszenie, jeśli nie utworzono kontenera kluczy.

Konstruktory

CspKeyContainerInfo(CspParameters)

Inicjuje CspKeyContainerInfo nowe wystąpienie klasy przy użyciu określonych parametrów.

Właściwości

Accessible

Pobiera wartość wskazującą, czy klucz w kontenerze kluczy jest dostępny.

CryptoKeySecurity

CryptoKeySecurity Pobiera obiekt reprezentujący prawa dostępu i reguły inspekcji dla kontenera.

Exportable

Pobiera wartość wskazującą, czy klucz można wyeksportować z kontenera kluczy.

HardwareDevice

Pobiera wartość wskazującą, czy klucz jest kluczem sprzętowym.

KeyContainerName

Pobiera nazwę kontenera kluczy.

KeyNumber

Pobiera wartość, która opisuje, czy klucz asymetryczny został utworzony jako klucz podpisu, czy klucz wymiany.

MachineKeyStore

Pobiera wartość wskazującą, czy klucz pochodzi z zestawu kluczy maszyny.

Protected

Pobiera wartość wskazującą, czy para kluczy jest chroniona.

ProviderName

Pobiera nazwę dostawcy klucza.

ProviderType

Pobiera typ dostawcy klucza.

RandomlyGenerated

Pobiera wartość wskazującą, czy kontener kluczy został losowo wygenerowany przez zarządzaną klasę kryptografii.

Removable

Pobiera wartość wskazującą, czy klucz można usunąć z kontenera kluczy.

UniqueKeyContainerName

Pobiera unikatową nazwę kontenera kluczy.

Metody

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy