X500DistinguishedName 类
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
表示 X509 证书的可分辨名称。 无法继承此类。
public ref class X500DistinguishedName sealed : System::Security::Cryptography::AsnEncodedData
public sealed class X500DistinguishedName : System.Security.Cryptography.AsnEncodedData
type X500DistinguishedName = class
inherit AsnEncodedData
Public NotInheritable Class X500DistinguishedName
Inherits AsnEncodedData
- 继承
下面的代码示例演示如何使用 X500DistinguishedName 类。
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
class X500Sample
{
static void Main()
{
try
{
X509Store store = new("MY", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = store.Certificates;
X509Certificate2Collection fcollection = collection.Find(
X509FindType.FindByTimeValid,
DateTime.Now, false
);
X509Certificate2Collection scollection = X509Certificate2UI.SelectFromCollection(
fcollection,
"Test Certificate Select",
"Select a certificate from the following list to get information on that certificate",
X509SelectionFlag.MultiSelection
);
Console.WriteLine($"Number of certificates: {scollection.Count}{Environment.NewLine}");
foreach (X509Certificate2 x509 in scollection)
{
X500DistinguishedName dname = new(
x509.SubjectName.Name,
X500DistinguishedNameFlags.Reversed | X500DistinguishedNameFlags.UseSemicolons
);
Console.WriteLine("X500DistinguishedName: {0}{1}", dname.Name, Environment.NewLine);
x509.Reset();
}
store.Close();
}
catch (CryptographicException)
{
Console.WriteLine("Information could not be written out for this certificate.");
}
}
}
Imports System.Security.Cryptography.X509Certificates
Class X500Sample
Shared s_msg As String
Shared Sub Main()
Try
Dim store As New X509Store("MY", StoreLocation.CurrentUser)
store.Open(OpenFlags.ReadOnly Or OpenFlags.OpenExistingOnly)
Dim collection As X509Certificate2Collection = store.Certificates
Dim fcollection As X509Certificate2Collection = collection.Find(X509FindType.FindByTimeValid, Date.Now, False)
Dim scollection As X509Certificate2Collection = X509Certificate2UI.SelectFromCollection(
fcollection,
"Test Certificate Select",
"Select a certificate from the following list to get information on that certificate",
X509SelectionFlag.MultiSelection
)
s_msg = "Number of certificates: " & scollection.Count & Environment.NewLine
Console.WriteLine(s_msg)
Dim x509 As X509Certificate2
For Each x509 In scollection
Dim dname As New X500DistinguishedName(
x509.SubjectName.Name,
X500DistinguishedNameFlags.Reversed Or X500DistinguishedNameFlags.UseSemicolons
)
s_msg = "X500DistinguishedName: " & dname.Name & Environment.NewLine
Console.WriteLine(s_msg)
x509.Reset()
Next x509
store.Close()
Catch e As Exception
s_msg = "Error: Information could not be written out for this certificate."
Console.WriteLine(s_msg)
End Try
End Sub
End Class
此类类似于 SubjectName 或 IssuerName 属性的扩展,该属性是证书要颁发给的人员或实体的名称。 X.500 是分布式目录服务的国际标准。 可分辨名称使用以下格式:
[X500:/C=CountryCode/O=Organization/OU=OrganizationUnit/CN=CommonName]
以下字段长度限制适用:
田 | 长度限制 |
---|---|
CountryCode | 2 个字符 |
组织 | 最多 64 个字符 |
OrganizationUnit | 最多 32 个字符 |
CommonName | 最多 64 个字符 |
以下准则适用:
字段值可以是大写或小写。
分隔符是斜杠标记(/),必须在第一个值之前和后续值之间显示。
分隔符后跟空格。
下面是格式正确的名称的示例:[X500:/ C=US/ O=Microsoft/ OU=WGA/ CN=TedSt]
X500Distinguished |
使用指定的 AsnEncodedData 对象初始化 X500DistinguishedName 类的新实例。 |
X500Distinguished |
使用指定字节数组中的信息初始化 X500DistinguishedName 类的新实例。 |
X500Distinguished |
使用所提供的数据中的信息初始化 X500DistinguishedName 类的新实例。 |
X500Distinguished |
使用指定的字符串和 X500DistinguishedNameFlags 标志初始化 X500DistinguishedName 类的新实例。 |
X500Distinguished |
使用指定字符串中的信息初始化 X500DistinguishedName 类的新实例。 |
X500Distinguished |
使用指定的 X500DistinguishedName 对象初始化 X500DistinguishedName 类的新实例。 |
Name |
从 X500 证书中获取逗号分隔的可分辨名称。 |
Oid |
获取或设置 AsnEncodedData 对象的 Oid 值。 (继承自 AsnEncodedData) |
Raw |
获取或设置字节数组中表示的抽象语法表示法一(ASN.1)编码的数据。 (继承自 AsnEncodedData) |
Copy |
从 AsnEncodedData 对象复制信息。 (继承自 AsnEncodedData) |
Decode(X500Distinguished |
使用 |
Enumerate |
循环访问此可分辨名称值内的 RelativeDistinguishedName 值。 |
Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
Format(Boolean) |
返回 X500 可分辨名称的格式版本,用于打印或输出到文本窗口或控制台。 |
Get |
用作默认哈希函数。 (继承自 Object) |
Get |
获取当前实例的 Type。 (继承自 Object) |
Memberwise |
创建当前 Object的浅表副本。 (继承自 Object) |
To |
返回一个表示当前对象的字符串。 (继承自 Object) |
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 2.0, 3.0, 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 | 1.3, 1.4, 1.6, 2.0, 2.1 |