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);
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

所需屬性的名稱。The name of the desired property.

options
CngPropertyOptions

列舉型別值的位元組合,指定具名屬性的選項。A bitwise combination of the enumeration values that specify options for the named property.

傳回

CngProperty

物件,包含指定屬性未經處理的值。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. 取得屬性的一般方式是使用類別所提供的屬性存取子 CngKeyThe 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/catchYou should call the HasProperty method first to avoid the exception instead of wrapping the method call in a try/catch block.

適用於