CspKeyContainerInfo 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供有关加密密钥对的其他信息。 此类不能被继承。
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
- 继承
-
CspKeyContainerInfo
- 属性
示例
下面的代码示例创建一个密钥容器并检索有关该容器的信息。
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
注解
使用此类获取有关密钥对的其他信息,例如密钥容器名称或密钥编号。
如果随机密钥由 RSACryptoServiceProvider 该密钥 DSACryptoServiceProvider或密钥生成,则在调用使用该密钥的方法之前,将不会创建密钥容器。 如果尚未创建密钥容器,该类的某些 CspKeyContainerInfo 属性将引发 CryptographicException 该属性。
构造函数
| 名称 | 说明 |
|---|---|
| CspKeyContainerInfo(CspParameters) |
使用指定的参数初始化类的新实例 CspKeyContainerInfo 。 |
属性
| 名称 | 说明 |
|---|---|
| Accessible |
获取一个值,该值指示密钥容器中的密钥是否可访问。 |
| CryptoKeySecurity |
获取一个 CryptoKeySecurity 对象,该对象表示容器的访问权限和审核规则。 |
| Exportable |
获取一个值,该值指示是否可以从密钥容器导出密钥。 |
| HardwareDevice |
获取一个值,该值指示密钥是否为硬件密钥。 |
| KeyContainerName |
获取密钥容器名称。 |
| KeyNumber |
获取一个值,该值描述非对称密钥是创建为签名密钥还是交换密钥。 |
| MachineKeyStore |
获取一个值,该值指示密钥是否来自计算机密钥集。 |
| Protected |
获取一个值,该值指示密钥对是否受保护。 |
| ProviderName |
获取密钥的提供程序名称。 |
| ProviderType |
获取密钥的提供程序类型。 |
| RandomlyGenerated |
获取一个值,该值指示密钥容器是否由托管加密类随机生成。 |
| Removable |
获取一个值,该值指示是否可以从密钥容器中删除密钥。 |
| UniqueKeyContainerName |
获取唯一键容器名称。 |
方法
| 名称 | 说明 |
|---|---|
| Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
| GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
| GetType() |
获取当前实例的 Type。 (继承自 Object) |
| MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
| ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |