<PackageReference Include="System.Security.Cryptography.Cng" Version="5.0.0-preview.3.20214.6" />

System.Security.Cryptography.CngKey

public sealed class CngKey : IDisposable
Defines the core functionality for keys that are used with Cryptography Next Generation (CNG) objects.
public CngAlgorithm Algorithm { get; }

Gets the algorithm that is used by the key.

Gets the algorithm group that is used by the key.

Gets the export policy that is used by the key.

public SafeNCryptKeyHandle Handle { get; }

Gets a safe handle that represents a native key (NCRYPT_KEY_HANDLE).

public bool IsEphemeral { get; }

Gets the persistence state of the key.

public bool IsMachineKey { get; }

Gets the scope (machine or user) of the key.

public string KeyName { get; }

Gets the name of the key.

public int KeySize { get; }

Gets the key size in bits.

public CngKeyUsages KeyUsage { get; }

Gets the cryptographic operations specified by the key.

public IntPtr ParentWindowHandle { get; set; }

Gets or sets the window handle (HWND) that should be used for user interface (UI) prompts caused by accessing the key.

public CngProvider Provider { get; }

Gets the key storage provider (KSP) that manages the key.

Gets a native handle (an NCRYPT_PROV_HANDLE) to the key storage provider (KSP).

public CngUIPolicy UIPolicy { get; }

Gets parameters that control the user interface (UI) for accessing the key.

public string UniqueName { get; }

Gets the unique name for the key.

public static CngKey Create(CngAlgorithm algorithm)

Creates a CngKey object that can be used with the specified algorithm.

public static CngKey Create(CngAlgorithm algorithm, string keyName)

Creates a named CngKey object that provides the specified algorithm.

public static CngKey Create(CngAlgorithm algorithm, string keyName, CngKeyCreationParameters creationParameters)

Creates a named CngKey object that provides the specified algorithm, using the supplied key creation parameters.

public static bool Exists(string keyName)

Checks to see whether a named key exists in the default key storage provider (KSP).

public static bool Exists(string keyName, CngProvider provider)

Checks to see whether a named key exists in the specified key storage provider (KSP).

public static bool Exists(string keyName, CngProvider provider, CngKeyOpenOptions options)

Checks to see whether a named key exists in the specified key storage provider (KSP), according to the specified options.

public static CngKey Import(byte[] keyBlob, CngKeyBlobFormat format)

Creates a new key by importing the specified key material into the default key storage provider (KSP) and using the specified format.

public static CngKey Import(byte[] keyBlob, CngKeyBlobFormat format, CngProvider provider)

Creates a new key by importing the specified key material into the specified key storage provider (KSP), using the specified format.

public static CngKey Open(SafeNCryptKeyHandle keyHandle, CngKeyHandleOpenOptions keyHandleOpenOptions)

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

public static CngKey Open(string keyName)

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

public static CngKey Open(string keyName, CngProvider provider)

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

public static CngKey Open(string keyName, CngProvider provider, CngKeyOpenOptions openOptions)

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 void Delete()

Removes the key that is associated with the object.

public void Dispose()

Releases all resources used by the current instance of the CngKey class.

public byte[] Export(CngKeyBlobFormat format)

Exports the key material into a BLOB, in the specified format.

public CngProperty GetProperty(string name, CngPropertyOptions options)

Gets a property, given a name and a set of property options.

public bool HasProperty(string name, CngPropertyOptions options)

Checks to see whether the specified property exists on the key.

public void SetProperty(CngProperty property)

Sets a named property on the key.