CngKey.GetProperty(String, CngPropertyOptions) 方法

定义

获取一个属性,给定一个名称和一组属性选项。

public:
 System::Security::Cryptography::CngProperty GetProperty(System::String ^ name, System::Security::Cryptography::CngPropertyOptions options);
public System.Security.Cryptography.CngProperty GetProperty(string name, System.Security.Cryptography.CngPropertyOptions options);
[System.Security.SecurityCritical]
public System.Security.Cryptography.CngProperty GetProperty(string name, System.Security.Cryptography.CngPropertyOptions options);
member this.GetProperty : string * System.Security.Cryptography.CngPropertyOptions -> System.Security.Cryptography.CngProperty
[<System.Security.SecurityCritical>]
member this.GetProperty : string * System.Security.Cryptography.CngPropertyOptions -> System.Security.Cryptography.CngProperty
Public Function GetProperty (name As String, options As CngPropertyOptions) As CngProperty

参数

name
String

所需属性的名称。

options
CngPropertyOptions

枚举值的按位组合,指定命名属性的选项。

返回

包含指定属性的原始值的对象。

属性

例外

namenull

所有其他错误。

注解

此方法的目的是返回键的任意属性的值。 检索属性的典型方法是使用类提供 CngKey 的属性访问器。 CngKey 为多个属性提供包装器,但并非全部属性。 该方法 GetProperty 主要用于访问未包装的属性的值。

在以下情况下,此方法非常有用:

  • 新版本的操作系统支持一个新的加密下一代(CNG)密钥属性,该属性没有包装器。

  • 将自定义属性添加到密钥。

options 参数专门用于指示以下内容:

  • 属性是内置属性还是自定义属性。

  • 属性是否应随键一起保留。

这些选项必须与属性设置的值匹配,否则找不到该属性。

CryptographicException 如果找不到该属性,则引发 。 应首先调用 HasProperty 该方法以避免异常,而不是将方法调用包装在块中 try/catch

适用于