Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

CngKey.Open Method (SafeNCryptKeyHandle, CngKeyHandleOpenOptions)

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

Namespace:  System.Security.Cryptography
Assembly:  System.Core (in System.Core.dll)
[SecurityPermissionAttribute(SecurityAction.Demand, UnmanagedCode = true)]
public static CngKey Open(
	SafeNCryptKeyHandle keyHandle,
	CngKeyHandleOpenOptions keyHandleOpenOptions
)

Parameters

keyHandle
Type: Microsoft.Win32.SafeHandles.SafeNCryptKeyHandle

A handle to an existing key.

keyHandleOpenOptions
Type: System.Security.Cryptography.CngKeyHandleOpenOptions

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

Return Value

Type: System.Security.Cryptography.CngKey
An existing key.
ExceptionCondition
ArgumentNullException

keyHandle is null.

ArgumentException

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.

PlatformNotSupportedException

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

CryptographicException

All other errors.

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.

.NET Framework

Supported in: 4.5.1, 4.5, 4, 3.5

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.