CngKey.Open 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
建立一個代表現有金鑰的物件實例 CngKey 。
多載
| 名稱 | Description |
|---|---|
| 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);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.Cryptography.CngKey Open(string keyName);
public static System.Security.Cryptography.CngKey Open(string keyName);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member Open : string -> System.Security.Cryptography.CngKey
static member Open : string -> System.Security.Cryptography.CngKey
Public Shared Function Open (keyName As String) As CngKey
參數
- keyName
- String
索引鍵的名稱。
傳回
一把現有的鑰匙。
- 屬性
例外狀況
keyName 是 null。
此系統不支援密碼學下一代(CNG)。
其他所有錯誤。
備註
此超載使用以下預設值:
金鑰儲存提供者(KSP): MicrosoftSoftwareKeyStorageProvider。 如果你想指定另一個 KSP,可以用超載。Open(String, CngProvider)
關鍵未開放選項: CngKeyOpenOptions.None
適用於
Open(SafeNCryptKeyHandle, CngKeyHandleOpenOptions)
透過使用現有金鑰的句柄來建立物件實 CngKey 例。
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);
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);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member Open : Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle * System.Security.Cryptography.CngKeyHandleOpenOptions -> System.Security.Cryptography.CngKey
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 短暫鍵還是命名鍵。
傳回
一把現有的鑰匙。
- 屬性
例外狀況
keyHandle 是 null。
keyHandle 無效或畸形,或已經關閉。 若金鑰是由通用語言執行時(CLR)建立的臨時金鑰,但未指定值, EphemeralKey 則此例外也會被拋出。
此系統不支援密碼學下一代(CNG)。
其他所有錯誤。
備註
這種過載讓進階使用者即使依賴平台調用或 C++ 的託管互通能力,也能使用 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);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.Cryptography.CngKey Open(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")>]
static member Open : string * System.Security.Cryptography.CngProvider -> System.Security.Cryptography.CngKey
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。
傳回
一把現有的鑰匙。
- 屬性
例外狀況
keyName 或 provider 為 null。
此系統不支援密碼學下一代(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);
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.Cryptography.CngKey Open(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);
[<System.Runtime.Versioning.SupportedOSPlatform("windows")>]
static member Open : string * System.Security.Cryptography.CngProvider * System.Security.Cryptography.CngKeyOpenOptions -> System.Security.Cryptography.CngKey
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 提示。
傳回
一把現有的鑰匙。
- 屬性
例外狀況
keyName 或 provider 為 null。
此系統不支援密碼學下一代(CNG)。
其他所有錯誤。
備註
與 Open(String) 方法過載不同,這個過載允許你同時指定提供者和開啟金鑰選項。