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 无效或格式不正确或已经被关闭。 如果密钥是由公共语言运行时 (CLR) 创建的暂时密钥,但未指定 EphemeralKey 值,也会引发此异常。

此系统上不支持下一代加密技术 (CNG)。

所有其他错误。

注解

此重载使高级用户能够使用 CNG 类,即使它们依赖于平台调用或 C++ 的托管互操作功能。 例如,如果本机库将密钥作为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)与方法重载不同,此重载允许指定提供程序。 此外,将创建并绑定到密钥的None默认值CngKeyOpenOptions

适用于

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)与方法重载不同,此重载允许你同时指定提供程序和密钥打开选项。

适用于