Szerkesztés

Megosztás a következőn keresztül:


CngKey.Open Method

Definition

Creates an instance of an CngKey object that represents an existing key.

Overloads

Open(String)

Creates an instance of an CngKey object that represents an existing named key.

Open(SafeNCryptKeyHandle, CngKeyHandleOpenOptions)

Creates an instance of an CngKey object by using a handle to an existing key.

Open(String, CngProvider)

Creates an instance of an CngKey object that represents an existing named key, using the specified key storage provider (KSP).

Open(String, CngProvider, CngKeyOpenOptions)

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)

Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs

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

Parameters

keyName
String

The name of the key.

Returns

An existing key.

Attributes

Exceptions

keyName is null.

Cryptography Next Generation (CNG) is not supported on this system.

All other errors.

Remarks

This overload uses the following defaults:

Applies to

Open(SafeNCryptKeyHandle, CngKeyHandleOpenOptions)

Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs

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.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

Parameters

keyHandle
SafeNCryptKeyHandle

A handle to an existing key.

keyHandleOpenOptions
CngKeyHandleOpenOptions

One of the enumeration values that indicates whether keyHandle represents an ephemeral key or a named key.

Returns

An existing key.

Attributes

Exceptions

keyHandle is null.

keyHandle is invalid or malformed, or it is already closed. 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.

Cryptography Next Generation (CNG) is not supported on this system.

All other errors.

Remarks

This overload enables advanced users to use the CNG classes even if they rely on platform invoke or the managed interop capability of C++. 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. Several properties of the CngKey class rely on this value to be correct. Therefore, make sure that you pass the correct flag value to the Open methods.

Applies to

Open(String, CngProvider)

Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs

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

Parameters

keyName
String

The name of the key.

provider
CngProvider

The KSP that contains the key.

Returns

An existing key.

Attributes

Exceptions

keyName or provider is null.

Cryptography Next Generation (CNG) is not supported on this system.

All other errors.

Remarks

Unlike the Open(String) method overload, this overload lets you specify the provider. In addition, a default CngKeyOpenOptions value of None is created and bound to the key.

Applies to

Open(String, CngProvider, CngKeyOpenOptions)

Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs
Source:
Cng.NotSupported.cs

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.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

Parameters

keyName
String

The name of the key.

provider
CngProvider

The KSP that contains the key.

openOptions
CngKeyOpenOptions

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.

Returns

An existing key.

Attributes

Exceptions

keyName or provider is null.

Cryptography Next Generation (CNG) is not supported on this system.

All other errors.

Remarks

Unlike the Open(String) method overload, this overload lets you specify both the provider and the key open options.

Applies to