CspKeyContainerInfo Classe

Definição

Fornece informações adicionais sobre um par de chaves criptográficas. Essa classe não pode ser herdada.

public ref class CspKeyContainerInfo sealed
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class CspKeyContainerInfo
public sealed class CspKeyContainerInfo
[<System.Runtime.InteropServices.ComVisible(true)>]
type CspKeyContainerInfo = class
type CspKeyContainerInfo = class
Public NotInheritable Class CspKeyContainerInfo
Herança
CspKeyContainerInfo
Atributos

Exemplos

O exemplo de código a seguir cria um contêiner de chave e recupera informações sobre esse contêiner.

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

Comentários

Use essa classe para obter informações adicionais sobre um par de chaves, como o nome do contêiner de chave ou o número da chave.

Nos casos em que uma chave aleatória é gerada pelo ou DSACryptoServiceProviderpelo RSACryptoServiceProvider contêiner de chave, um contêiner de chave não será criado até que você chame um método que use a chave. Algumas propriedades da CspKeyContainerInfo classe gerarão um CryptographicException se um contêiner de chave não tiver sido criado.

Construtores

Nome Description
CspKeyContainerInfo(CspParameters)

Inicializa uma nova instância da CspKeyContainerInfo classe usando os parâmetros especificados.

Propriedades

Nome Description
Accessible

Obtém um valor que indica se uma chave em um contêiner de chave está acessível.

CryptoKeySecurity

Obtém um CryptoKeySecurity objeto que representa direitos de acesso e regras de auditoria para um contêiner.

Exportable

Obtém um valor que indica se uma chave pode ser exportada de um contêiner de chave.

HardwareDevice

Obtém um valor que indica se uma chave é uma chave de hardware.

KeyContainerName

Obtém um nome de contêiner de chave.

KeyNumber

Obtém um valor que descreve se uma chave assimétrica foi criada como uma chave de assinatura ou uma chave de troca.

MachineKeyStore

Obtém um valor que indica se uma chave é de um conjunto de chaves do computador.

Protected

Obtém um valor que indica se um par de chaves está protegido.

ProviderName

Obtém o nome do provedor de uma chave.

ProviderType

Obtém o tipo de provedor de uma chave.

RandomlyGenerated

Obtém um valor que indica se um contêiner de chave foi gerado aleatoriamente por uma classe de criptografia gerenciada.

Removable

Obtém um valor que indica se uma chave pode ser removida de um contêiner de chave.

UniqueKeyContainerName

Obtém um nome de contêiner de chave exclusivo.

Métodos

Nome Description
Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.

(Herdado de Object)
GetHashCode()

Serve como a função hash predefinida.

(Herdado de Object)
GetType()

Obtém o Type da instância atual.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Objectatual.

(Herdado de Object)
ToString()

Retorna uma cadeia de caracteres que representa o objeto atual.

(Herdado de Object)

Aplica-se a