CspKeyContainerInfo Classe
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Fournit des informations supplémentaires sur une paire de clés de chiffrement. Cette classe ne peut pas être héritée.
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
- Héritage
-
CspKeyContainerInfo
- Attributs
Exemples
L’exemple de code suivant crée un conteneur de clés et récupère des informations sur ce conteneur.
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
Remarques
Utilisez cette classe pour obtenir des informations supplémentaires sur une paire de clés, telles que le nom du conteneur de clés ou le numéro de clé.
Dans les cas où une clé aléatoire est générée par le ou le RSACryptoServiceProviderDSACryptoServiceProviderconteneur de clés, un conteneur de clés ne sera créé que lorsque vous appelez une méthode qui utilise la clé. Certaines propriétés de la CspKeyContainerInfo classe lèvent une CryptographicException valeur si un conteneur de clés n’a pas été créé.
Constructeurs
| Nom | Description |
|---|---|
| CspKeyContainerInfo(CspParameters) |
Initialise une nouvelle instance de la classe à l’aide CspKeyContainerInfo des paramètres spécifiés. |
Propriétés
| Nom | Description |
|---|---|
| Accessible |
Obtient une valeur indiquant si une clé dans un conteneur de clés est accessible. |
| CryptoKeySecurity |
Obtient un CryptoKeySecurity objet qui représente les droits d’accès et les règles d’audit d’un conteneur. |
| Exportable |
Obtient une valeur indiquant si une clé peut être exportée à partir d’un conteneur de clés. |
| HardwareDevice |
Obtient une valeur indiquant si une clé est une clé matérielle. |
| KeyContainerName |
Obtient un nom de conteneur de clé. |
| KeyNumber |
Obtient une valeur qui décrit si une clé asymétrique a été créée en tant que clé de signature ou clé d’échange. |
| MachineKeyStore |
Obtient une valeur indiquant si une clé provient d’un jeu de clés d’ordinateur. |
| Protected |
Obtient une valeur indiquant si une paire de clés est protégée. |
| ProviderName |
Obtient le nom du fournisseur d’une clé. |
| ProviderType |
Obtient le type de fournisseur d’une clé. |
| RandomlyGenerated |
Obtient une valeur indiquant si un conteneur de clés a été généré de façon aléatoire par une classe de chiffrement managée. |
| Removable |
Obtient une valeur indiquant si une clé peut être supprimée d’un conteneur de clés. |
| UniqueKeyContainerName |
Obtient un nom de conteneur de clé unique. |
Méthodes
| Nom | Description |
|---|---|
| Equals(Object) |
Détermine si l’objet spécifié est égal à l’objet actuel. (Hérité de Object) |
| GetHashCode() |
Sert de fonction de hachage par défaut. (Hérité de Object) |
| GetType() |
Obtient la Type de l’instance actuelle. (Hérité de Object) |
| MemberwiseClone() |
Crée une copie superficielle du Objectactuel. (Hérité de Object) |
| ToString() |
Retourne une chaîne qui représente l’objet actuel. (Hérité de Object) |