CspKeyContainerInfo.KeyNumber 属性     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取一个值,该值描述非对称密钥被创建为签名密钥还是交换密钥。
public:
 property System::Security::Cryptography::KeyNumber KeyNumber { System::Security::Cryptography::KeyNumber get(); };public System.Security.Cryptography.KeyNumber KeyNumber { get; }member this.KeyNumber : System.Security.Cryptography.KeyNumberPublic ReadOnly Property KeyNumber As KeyNumber属性值
描述非对称密钥被创建为签名密钥还是交换密钥的其中一个 KeyNumber 值。
示例
下面的代码示例创建一个密钥容器,并检索有关该容器的信息。
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
注解
属性的值KeyNumber派生自KeyNumber用于初始化 CspKeyContainerInfo 对象的 字段CspParameters。
交换密钥是一种非对称密钥对,用于加密会话密钥,以便可以安全地存储和与其他用户交换这些密钥。  值 Exchange 指定交换密钥。  此值对应于 AT_KEYEXCHANGE 非托管 Microsoft 加密 API (CAPI) 中使用的值。
签名密钥是一种非对称密钥对,用于对 (数字签名) 消息或文件进行身份验证。  值 Signature 指定签名密钥。  此值对应于 AT_SIGNATURE CAPI 中使用的值。