CngKey.Open 方法

定義

建立代表現有金鑰的 CngKey 物件執行個體。

多載

Open(String)

建立代表現有具名金鑰的 CngKey 物件執行個體。

Open(SafeNCryptKeyHandle, CngKeyHandleOpenOptions)

使用現有金鑰的控制代碼建立 CngKey 物件的執行個體。

Open(String, CngProvider)

使用指定的金鑰儲存提供者 (KSP) 建立代表現有具名金鑰的 CngKey 物件執行個體。

Open(String, CngProvider, CngKeyOpenOptions)

使用指定的金鑰儲存提供者 (KSP) 和金鑰開啟選項,建立代表現有具名金鑰的 CngKey 物件執行個體。

Open(String)

建立代表現有具名金鑰的 CngKey 物件執行個體。

public:
 static System::Security::Cryptography::CngKey ^ Open(System::String ^ keyName);
public static System.Security.Cryptography.CngKey Open (string keyName);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.Cryptography.CngKey Open (string keyName);
static member Open : string -> System.Security.Cryptography.CngKey
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member Open : string -> System.Security.Cryptography.CngKey
Public Shared Function Open (keyName As String) As CngKey

參數

keyName
String

索引鍵名稱。

傳回

CngKey

現有金鑰。

屬性

例外狀況

keyNamenull

此系統不支援新一代密碼編譯 (CNG)。

所有其他錯誤。

備註

此多載會使用下列預設值:

適用於

Open(SafeNCryptKeyHandle, CngKeyHandleOpenOptions)

使用現有金鑰的控制代碼建立 CngKey 物件的執行個體。

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.Runtime.Versioning.SupportedOSPlatform("windows")]
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.Runtime.Versioning.SupportedOSPlatform("windows")>]
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

現有金鑰的控制代碼。

keyHandleOpenOptions
CngKeyHandleOpenOptions

其中一個列舉值,指出 keyHandle 是否代表暫時金鑰或具名金鑰。

傳回

CngKey

現有金鑰。

屬性

例外狀況

keyHandlenull

keyHandle 無效或不正確,或是已關閉。 如果金鑰是由 Common Language Runtime (CLR) 建立的暫時金鑰,但是未指定 EphemeralKey 值,則同樣會擲回這個例外狀況。

此系統不支援新一代密碼編譯 (CNG)。

所有其他錯誤。

備註

即使進階使用者依賴平臺叫用或 C++ 的 Managed Interop 功能,此多載也可讓進階使用者使用 CNG 類別。 例如,如果您有將金鑰傳回為NCRYPT_KEY_HANDLE的原生程式庫,此多載可讓您在金鑰周圍建立受控包裝函式,並使用 CNG 類別操作金鑰。

當您使用金鑰控制碼開啟金鑰時,您無法判斷金鑰的暫時狀態,而且必須自行指定。 類別 CngKey 的數個屬性依賴這個值來正確。 因此,請確定您將正確的旗標值傳遞至 Open 方法。

適用於

Open(String, CngProvider)

使用指定的金鑰儲存提供者 (KSP) 建立代表現有具名金鑰的 CngKey 物件執行個體。

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);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
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
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
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

索引鍵名稱。

provider
CngProvider

包含金鑰的 KSP。

傳回

CngKey

現有金鑰。

屬性

例外狀況

keyNameprovidernull

此系統不支援新一代密碼編譯 (CNG)。

所有其他錯誤。

備註

Open(String)不同于方法多載,此多載可讓您指定提供者。 此外,會建立 並系結至索引鍵的預設值 CngKeyOpenOptions None

適用於

Open(String, CngProvider, CngKeyOpenOptions)

使用指定的金鑰儲存提供者 (KSP) 和金鑰開啟選項,建立代表現有具名金鑰的 CngKey 物件執行個體。

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.Runtime.Versioning.SupportedOSPlatform("windows")]
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.Runtime.Versioning.SupportedOSPlatform("windows")>]
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

索引鍵名稱。

provider
CngProvider

包含金鑰的 KSP。

openOptions
CngKeyOpenOptions

列舉值的位元組合,可指定開啟金鑰的選項,例如,金鑰是從何處開啟 (電腦或使用者存放裝置),以及是否要隱藏 UI 提示。

傳回

CngKey

現有金鑰。

屬性

例外狀況

keyNameprovidernull

此系統不支援新一代密碼編譯 (CNG)。

所有其他錯誤。

備註

Open(String)不同于方法多載,此多載可讓您同時指定提供者和金鑰開啟選項。

適用於