CngKey.Exists 方法

定义

检查特定密钥存储提供程序 (KSP) 中是否存在已命名的密钥。

重载

Exists(String)

检查默认的密钥存储提供程序 (KSP) 中是否存在已命名的密钥。

Exists(String, CngProvider)

检查指定的密钥存储提供程序 (KSP) 中是否存在已命名的密钥。

Exists(String, CngProvider, CngKeyOpenOptions)

根据指定的选项,检查指定的密钥存储提供程序 (KSP) 中是否存在已命名的密钥。

Exists(String)

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

检查默认的密钥存储提供程序 (KSP) 中是否存在已命名的密钥。

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

参数

keyName
String

键名称。

返回

如果默认的 KSP 中存在该已命名的密钥,则为 true;否则为 false

属性

例外

keyNamenull

此系统上不支持下一代加密技术 (CNG)。

所有其他错误。

注解

默认 KSP 为 MicrosoftSoftwareKeyStorageProvider

适用于

.NET 9 和其他版本
产品 版本
.NET Core 1.0, Core 1.1, 6, 7, 8, 9
.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, 2.1
Windows Desktop 3.0, 3.1, 5

Exists(String, CngProvider)

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

检查指定的密钥存储提供程序 (KSP) 中是否存在已命名的密钥。

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

参数

keyName
String

键名称。

provider
CngProvider

用于检查密钥的 KSP。

返回

如果指定的提供程序中存在该已命名的密钥,则为 true;否则为 false

属性

例外

keyNameprovidernull

此系统上不支持下一代加密技术 (CNG)。

所有其他错误。

注解

使用此重载检查 KSP 中是否存在除默认 KSP(即 MicrosoftSoftwareKeyStorageProvider)以外的键。

适用于

.NET 9 和其他版本
产品 版本
.NET Core 1.0, Core 1.1, 6, 7, 8, 9
.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, 2.1
Windows Desktop 3.0, 3.1, 5

Exists(String, CngProvider, CngKeyOpenOptions)

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

根据指定的选项,检查指定的密钥存储提供程序 (KSP) 中是否存在已命名的密钥。

C#
public static bool Exists (string keyName, System.Security.Cryptography.CngProvider provider, System.Security.Cryptography.CngKeyOpenOptions options);
C#
[System.Runtime.Versioning.SupportedOSPlatform("windows")]
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);

参数

keyName
String

键名称。

provider
CngProvider

用于搜索密钥的 KSP。

options
CngKeyOpenOptions

指定密钥打开选项的枚举值的按位组合。

返回

如果指定的提供程序中存在该已命名的密钥,则为 true;否则为 false

属性

例外

keyNameprovidernull

此系统上不支持下一代加密技术 (CNG)。

所有其他错误。

注解

使用此重载检查 KSP 中是否存在默认 MicrosoftSoftwareKeyStorageProvider的键,并指定键打开选项。

适用于

.NET 9 和其他版本
产品 版本
.NET Core 1.0, Core 1.1, 6, 7, 8, 9
.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, 2.1
Windows Desktop 3.0, 3.1, 5