CngKey.Exists Method

Definition

Checks for a named key in a specific key storage provider(KSP).

Overloads

Exists(String)

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

Exists(String, CngProvider)

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

Exists(String, CngProvider, CngKeyOpenOptions)

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

Exists(String)

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

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

C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static bool Exists(string keyName);
C#
public static bool Exists(string keyName);

Parameters

keyName
String

The key name.

Returns

true if the named key exists in the default KSP; otherwise, false.

Attributes

Exceptions

keyName is null.

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

All other errors.

Remarks

The default KSP is MicrosoftSoftwareKeyStorageProvider.

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

Exists(String, CngProvider)

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

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

C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static bool Exists(string keyName, System.Security.Cryptography.CngProvider provider);
C#
public static bool Exists(string keyName, System.Security.Cryptography.CngProvider provider);

Parameters

keyName
String

The key name.

provider
CngProvider

The KSP to check for the key.

Returns

true if the named key exists in the specified provider; otherwise, false.

Attributes

Exceptions

keyName or provider is null.

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

All other errors.

Remarks

Use this overload to check for the existence of a key in a KSP other than the default KSP, which is MicrosoftSoftwareKeyStorageProvider.

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

Exists(String, CngProvider, CngKeyOpenOptions)

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

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

C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
public static bool Exists(string keyName, System.Security.Cryptography.CngProvider provider, System.Security.Cryptography.CngKeyOpenOptions options);
C#
public static bool Exists(string keyName, System.Security.Cryptography.CngProvider provider, System.Security.Cryptography.CngKeyOpenOptions options);
C#
[System.Security.SecurityCritical]
public static bool Exists(string keyName, System.Security.Cryptography.CngProvider provider, System.Security.Cryptography.CngKeyOpenOptions options);

Parameters

keyName
String

The key name.

provider
CngProvider

The KSP to search for the key.

options
CngKeyOpenOptions

A bitwise combination of the enumeration values that specify options for opening a key.

Returns

true if the named key exists in the specified provider; otherwise, false.

Attributes

Exceptions

keyName or provider is null.

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

All other errors.

Remarks

Use this overload to check for the existence of a key in a KSP other than the default MicrosoftSoftwareKeyStorageProvider, and to specify key open options.

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