X500DistinguishedName 类

定义

表示 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

示例

下面的代码示例演示如何使用 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

注解

此类类似于 或 IssuerName 属性的扩展SubjectName,该属性是向其颁发证书的人员或实体的名称。 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]

构造函数

X500DistinguishedName(AsnEncodedData)

使用指定的 AsnEncodedData 对象初始化 X500DistinguishedName 类的新实例。

X500DistinguishedName(Byte[])

使用指定字节数组中的信息初始化 X500DistinguishedName 类的新实例。

X500DistinguishedName(ReadOnlySpan<Byte>)

使用所提供数据中的信息初始化 X500DistinguishedName 类的新实例。

X500DistinguishedName(String)

使用指定字符串中的信息初始化 X500DistinguishedName 类的新实例。

X500DistinguishedName(String, X500DistinguishedNameFlags)

使用指定的字符串和 X500DistinguishedName 标志初始化 X500DistinguishedNameFlags 类的新实例。

X500DistinguishedName(X500DistinguishedName)

使用指定的 X500DistinguishedName 对象初始化 X500DistinguishedName 类的新实例。

属性

Name

从 X500 证书获取逗号分隔的识别名。

Oid

获取或设置 Oid 对象的 AsnEncodedData 值。

(继承自 AsnEncodedData)
RawData

获取或设置以字节数组表示的 Abstract Syntax Notation One (ASN.1) 编码数据。

(继承自 AsnEncodedData)

方法

CopyFrom(AsnEncodedData)

AsnEncodedData 对象复制信息。

(继承自 AsnEncodedData)
Decode(X500DistinguishedNameFlags)

使用由 flag 参数指定的特征对识别名进行解码。

EnumerateRelativeDistinguishedNames(Boolean)

循环访问此可分辨名称值中的 RelativeDistinguishedName 值。

Equals(Object)

确定指定对象是否等于当前对象。

(继承自 Object)
Format(Boolean)

返回 X500 识别名的格式化版本,以便打印或输出到文本窗口或控制台。

GetHashCode()

作为默认哈希函数。

(继承自 Object)
GetType()

获取当前实例的 Type

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。

(继承自 Object)
ToString()

返回表示当前对象的字符串。

(继承自 Object)

适用于