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.

返回

现有密钥。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:

安全性

KeyContainerPermissionAccessEntryCollection
用于打开密钥容器的权限。for permission to open a key container. 需求值: DemandDemand value: Demand. 关联的枚举: OpenAssociated enumeration: Open

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

返回

现有密钥。An existing key.

属性

异常

keyHandlenullkeyHandle is null.

keyHandle 无效或格式不正确或已经被关闭。keyHandle is invalid or malformed, or it is already closed. 如果密钥是由公共语言运行时 (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.

注解

此重载使高级用户可以使用 CNG 类,即使它们依赖于的C++平台调用或托管互操作功能。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 方式返回密钥的本机库,则此重载使你可以围绕该密钥创建一个托管包装,并使用 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.

安全性

SecurityPermission
用于调用非托管代码的权限。for permission to call unmanaged code. 需求值: DemandDemand value: Demand. 关联的枚举: UnmanagedCodeAssociated enumeration: UnmanagedCode

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.

返回

现有密钥。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. 此外,还会创建 None 的默认 CngKeyOpenOptions 值,并将其绑定到密钥。In addition, a default CngKeyOpenOptions value of None is created and bound to the key.

安全性

KeyContainerPermissionAccessEntryCollection
用于打开密钥容器的权限。for permission to open a key container. 需求值: DemandDemand value: Demand. 关联的枚举: OpenAssociated enumeration: Open

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

返回

现有密钥。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.

安全性

KeyContainerPermissionAccessEntryCollection
用于打开密钥容器的权限。for permission to open a key container. 需求值: DemandDemand value: Demand. 关联的枚举: OpenAssociated enumeration: Open

适用于