CngKey.GetProperty(String, CngPropertyOptions) 方法

定义

在给定名称和一组属性选项的情况下,获取一个属性。Gets a property, given a name and a set of property options.

public:
 System::Security::Cryptography::CngProperty GetProperty(System::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
Public Function GetProperty (name As String, options As CngPropertyOptions) As CngProperty

参数

name
String

所需属性的名称。The name of the desired property.

options
CngPropertyOptions

指定已命名属性选项的枚举值的按位组合。A bitwise combination of the enumeration values that specify options for the named property.

返回

一个包含指定属性的原始值的对象。An object that contains the raw value of the specified property.

属性

异常

namenullname is null.

所有其他错误。All other errors.

注解

此方法的目的是返回键的任意属性的值。The purpose of this method is to return the value of an arbitrary property of the key. 检索属性的典型方法是使用CngKey类提供的属性访问器。The typical way to retrieve properties is by using the property accessors provided by the CngKey class. CngKey为多个(但不是全部)属性提供包装。CngKey provides wrappers for several, but not all, properties. GetProperty方法主要用于访问未包装的属性的值。The GetProperty method is primarily used to access the value of a property that is not wrapped.

此方法在以下情况下很有用:This method is useful in the following cases:

  • 新版本的操作系统支持没有包装的新的下一代加密技术(CNG)密钥属性。A new version of the operating system supports a new Cryptography Next Generation (CNG) key property that does not have a wrapper.

  • 将自定义属性添加到该密钥。You add a custom property to the key.

options参数专用于指示以下内容:The options parameter is specifically used to indicate the following:

  • 属性是内置的还是自定义的。Whether the property is built-in, or custom.

  • 是否应将属性与密钥一起保存。Whether the property should be persisted with the key.

这些选项必须与属性的设置值相匹配,否则将找不到属性。These options must match the value that the property was set with, or the property will not be found.

CryptographicException如果找不到该属性,则会引发。CryptographicException is thrown if the property cannot be found. 应该首先调用HasProperty方法以避免异常,而不是try/catch在块中包装方法调用。You should call the HasProperty method first to avoid the exception instead of wrapping the method call in a try/catch block.

安全性

SecurityPermission
用于调用非托管代码的权限。for permission to call unmanaged code. 需求值: LinkDemandDemand value: LinkDemand. 关联的枚举:UnmanagedCodeAssociated enumeration: UnmanagedCode

适用于