CngKey.Open 方法

定義

建立代表現有金鑰的 CngKey 物件執行個體。Creates an instance of an CngKey object that represents an existing key.

多載

Open(String)

建立代表現有具名金鑰的 CngKey 物件執行個體。Creates an instance of an CngKey object that represents an existing named key.

Open(SafeNCryptKeyHandle, CngKeyHandleOpenOptions)

使用現有金鑰的控制代碼建立 CngKey 物件的執行個體。Creates an instance of an CngKey object by using a handle to an existing key.

Open(String, CngProvider)

使用指定的金鑰儲存提供者 (KSP) 建立代表現有具名金鑰的 CngKey 物件執行個體。Creates an instance of an CngKey object that represents an existing named key, using the specified key storage provider (KSP).

Open(String, CngProvider, CngKeyOpenOptions)

使用指定的金鑰儲存提供者 (KSP) 和金鑰開啟選項,建立代表現有具名金鑰的 CngKey 物件執行個體。Creates an instance of an CngKey object that represents an existing named key, using the specified key storage provider (KSP) and key open options.

Open(String)

建立代表現有具名金鑰的 CngKey 物件執行個體。Creates an instance of an CngKey object that represents an existing named key.

public:
 static System::Security::Cryptography::CngKey ^ Open(System::String ^ keyName);
public static System.Security.Cryptography.CngKey Open (string keyName);
static member Open : string -> System.Security.Cryptography.CngKey
Public Shared Function Open (keyName As String) As CngKey

參數

keyName
String

索引鍵名稱。The name of the key.

傳回

CngKey

現有金鑰。An existing key.

例外狀況

keyNamenullkeyName is null.

此系統不支援新一代密碼編譯 (CNG)。Cryptography Next Generation (CNG) is not supported on this system.

所有其他錯誤。All other errors.

備註

這個多載會使用下列預設值:This overload uses the following defaults:

適用於

Open(SafeNCryptKeyHandle, CngKeyHandleOpenOptions)

使用現有金鑰的控制代碼建立 CngKey 物件的執行個體。Creates an instance of an CngKey object by using a handle to an existing key.

public:
 static System::Security::Cryptography::CngKey ^ Open(Microsoft::Win32::SafeHandles::SafeNCryptKeyHandle ^ keyHandle, System::Security::Cryptography::CngKeyHandleOpenOptions keyHandleOpenOptions);
public static System.Security.Cryptography.CngKey Open (Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle keyHandle, System.Security.Cryptography.CngKeyHandleOpenOptions keyHandleOpenOptions);
[System.Security.SecurityCritical]
public static System.Security.Cryptography.CngKey Open (Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle keyHandle, System.Security.Cryptography.CngKeyHandleOpenOptions keyHandleOpenOptions);
static member Open : Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle * System.Security.Cryptography.CngKeyHandleOpenOptions -> System.Security.Cryptography.CngKey
[<System.Security.SecurityCritical>]
static member Open : Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle * System.Security.Cryptography.CngKeyHandleOpenOptions -> System.Security.Cryptography.CngKey
Public Shared Function Open (keyHandle As SafeNCryptKeyHandle, keyHandleOpenOptions As CngKeyHandleOpenOptions) As CngKey

參數

keyHandle
SafeNCryptKeyHandle

現有金鑰的控制代碼。A handle to an existing key.

keyHandleOpenOptions
CngKeyHandleOpenOptions

其中一個列舉值,指出 keyHandle 是否代表暫時金鑰或具名金鑰。One of the enumeration values that indicates whether keyHandle represents an ephemeral key or a named key.

傳回

CngKey

現有金鑰。An existing key.

屬性

例外狀況

keyHandlenullkeyHandle is null.

keyHandle 無效或不正確,或是已關閉。keyHandle is invalid or malformed, or it is already closed. 如果金鑰是由 Common Language Runtime (CLR) 建立的暫時金鑰,但是未指定 EphemeralKey 值,則同樣會擲回這個例外狀況。This exception is also thrown if the key is an ephemeral key that is created by the common language runtime (CLR), but the EphemeralKey value is not specified.

此系統不支援新一代密碼編譯 (CNG)。Cryptography Next Generation (CNG) is not supported on this system.

所有其他錯誤。All other errors.

備註

此多載可讓 advanced users 使用 CNG 類別,即使它們依賴平台叫用或 c + + 的 managed interop 功能也一樣。This overload enables advanced users to use the CNG classes even if they rely on platform invoke or the managed interop capability of C++. 例如,如果您有原生程式庫以 NCRYPT_KEY_HANDLE 的方式傳回金鑰,這個多載可讓您建立金鑰周圍的 managed 包裝函式,並使用 CNG 類別來操作它。For example, if you have a native library that returns the key as an NCRYPT_KEY_HANDLE, this overload lets you create a managed wrapper around the key and use the CNG classes to manipulate it.

當您使用其控制碼開啟金鑰時,無法判斷金鑰的暫時狀態,必須自行指定。When you open a key by using its handle, you cannot determine the key's ephemeral state and must specify it yourself. 類別的數個屬性 CngKey 依賴此值來正確。Several properties of the CngKey class rely on this value to be correct. 因此,請確定您將正確的旗標值傳遞給 Open 方法。Therefore, make sure that you pass the correct flag value to the Open methods.

適用於

Open(String, CngProvider)

使用指定的金鑰儲存提供者 (KSP) 建立代表現有具名金鑰的 CngKey 物件執行個體。Creates an instance of an CngKey object that represents an existing named key, using the specified key storage provider (KSP).

public:
 static System::Security::Cryptography::CngKey ^ Open(System::String ^ keyName, System::Security::Cryptography::CngProvider ^ provider);
public static System.Security.Cryptography.CngKey Open (string keyName, System.Security.Cryptography.CngProvider provider);
static member Open : string * System.Security.Cryptography.CngProvider -> System.Security.Cryptography.CngKey
Public Shared Function Open (keyName As String, provider As CngProvider) As CngKey

參數

keyName
String

索引鍵名稱。The name of the key.

provider
CngProvider

包含金鑰的 KSP。The KSP that contains the key.

傳回

CngKey

現有金鑰。An existing key.

例外狀況

keyNameprovidernullkeyName or provider is null.

此系統不支援新一代密碼編譯 (CNG)。Cryptography Next Generation (CNG) is not supported on this system.

所有其他錯誤。All other errors.

備註

不同于 Open(String) 方法多載,這個多載可讓您指定提供者。Unlike the Open(String) method overload, this overload lets you specify the provider. 此外, CngKeyOpenOptions 也會建立的預設值並系結 None 至索引鍵。In addition, a default CngKeyOpenOptions value of None is created and bound to the key.

適用於

Open(String, CngProvider, CngKeyOpenOptions)

使用指定的金鑰儲存提供者 (KSP) 和金鑰開啟選項,建立代表現有具名金鑰的 CngKey 物件執行個體。Creates an instance of an CngKey object that represents an existing named key, using the specified key storage provider (KSP) and key open options.

public:
 static System::Security::Cryptography::CngKey ^ Open(System::String ^ keyName, System::Security::Cryptography::CngProvider ^ provider, System::Security::Cryptography::CngKeyOpenOptions openOptions);
public static System.Security.Cryptography.CngKey Open (string keyName, System.Security.Cryptography.CngProvider provider, System.Security.Cryptography.CngKeyOpenOptions openOptions);
[System.Security.SecurityCritical]
public static System.Security.Cryptography.CngKey Open (string keyName, System.Security.Cryptography.CngProvider provider, System.Security.Cryptography.CngKeyOpenOptions openOptions);
static member Open : string * System.Security.Cryptography.CngProvider * System.Security.Cryptography.CngKeyOpenOptions -> System.Security.Cryptography.CngKey
[<System.Security.SecurityCritical>]
static member Open : string * System.Security.Cryptography.CngProvider * System.Security.Cryptography.CngKeyOpenOptions -> System.Security.Cryptography.CngKey
Public Shared Function Open (keyName As String, provider As CngProvider, openOptions As CngKeyOpenOptions) As CngKey

參數

keyName
String

索引鍵名稱。The name of the key.

provider
CngProvider

包含金鑰的 KSP。The KSP that contains the key.

openOptions
CngKeyOpenOptions

列舉值的位元組合,可指定開啟金鑰的選項,例如,金鑰是從何處開啟 (電腦或使用者存放裝置),以及是否要隱藏 UI 提示。A bitwise combination of the enumeration values that specify options for opening the key, such as where the key is opened from (machine or user storage) and whether to suppress UI prompting.

傳回

CngKey

現有金鑰。An existing key.

屬性

例外狀況

keyNameprovidernullkeyName or provider is null.

此系統不支援新一代密碼編譯 (CNG)。Cryptography Next Generation (CNG) is not supported on this system.

所有其他錯誤。All other errors.

備註

不同于 Open(String) 方法多載,這個多載可讓您同時指定提供者和金鑰開啟選項。Unlike the Open(String) method overload, this overload lets you specify both the provider and the key open options.

適用於