CngKey.Create Method

Definition

Creates a CngKey object that represents a new key.

Overloads

Create(CngAlgorithm)

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

Create(CngAlgorithm, String)

Creates a named CngKey object that provides the specified algorithm.

Create(CngAlgorithm, String, CngKeyCreationParameters)

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

Create(CngAlgorithm)

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

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

C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm);
C#
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm);

Parameters

algorithm
CngAlgorithm

The algorithm that the key will be used with.

Returns

An ephemeral key.

Attributes

Exceptions

algorithm is null.

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

All other errors.

Remarks

This overload creates a key without a name, which means that the key is ephemeral (that is, it will not be persisted). It also creates a default CngKeyCreationParameters object that specifies a default CngProvider and other advanced parameters for the key.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
Windows Desktop 3.0, 3.1, 5

Create(CngAlgorithm, String)

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

Creates a named CngKey object that provides the specified algorithm.

C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string? keyName);
C#
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string? keyName);
C#
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string keyName);

Parameters

algorithm
CngAlgorithm

The algorithm that the key will be used with.

keyName
String

The key name. If a name is not provided, the key will not be persisted.

Returns

A persisted or ephemeral key that provides the specified algorithm.

Attributes

Exceptions

algorithm is null.

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

All other errors.

Remarks

If keyName is provided, this overload creates a persisted key. If keyName is not provided, the key will be ephemeral. This overload also creates a default CngKeyCreationParameters object that specifies a default CngProvider and other advanced parameters for the key.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
Windows Desktop 3.0, 3.1, 5

Create(CngAlgorithm, String, CngKeyCreationParameters)

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

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

C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string? keyName, System.Security.Cryptography.CngKeyCreationParameters? creationParameters);
C#
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string? keyName, System.Security.Cryptography.CngKeyCreationParameters? creationParameters);
C#
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string keyName, System.Security.Cryptography.CngKeyCreationParameters creationParameters);
C#
[System.Security.SecurityCritical]
public static System.Security.Cryptography.CngKey Create(System.Security.Cryptography.CngAlgorithm algorithm, string keyName, System.Security.Cryptography.CngKeyCreationParameters creationParameters);

Parameters

algorithm
CngAlgorithm

The algorithm that the key will be used with.

keyName
String

The key name. If a name is not provided, the key will not be persisted.

creationParameters
CngKeyCreationParameters

An object that specifies advanced parameters for the method, including the CngProvider.

Returns

A persisted or ephemeral key that provides the specified algorithm.

Attributes

Exceptions

algorithm is null.

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

All other errors.

Remarks

If keyName is provided, this overload creates a persisted key. If keyName is not provided, the key will be ephemeral.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 1.0, Core 1.1, 6, 7, 8, 9, 10
.NET Framework 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided), 2.1 (package-provided)
Windows Desktop 3.0, 3.1, 5