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]
构造函数
X500DistinguishedName(AsnEncodedData) |
使用指定的 AsnEncodedData 对象初始化 X500DistinguishedName 类的新实例。 |
X500DistinguishedName(Byte[]) |
使用指定字节数组中的信息初始化 X500DistinguishedName 类的新实例。 |
X500DistinguishedName(ReadOnlySpan<Byte>) |
使用所提供的数据中的信息初始化 X500DistinguishedName 类的新实例。 |
X500DistinguishedName(String, X500DistinguishedNameFlags) |
使用指定的字符串和 X500DistinguishedNameFlags 标志初始化 X500DistinguishedName 类的新实例。 |
X500DistinguishedName(String) |
使用指定字符串中的信息初始化 X500DistinguishedName 类的新实例。 |
X500DistinguishedName(X500DistinguishedName) |
使用指定的 X500DistinguishedName 对象初始化 X500DistinguishedName 类的新实例。 |
属性
Name |
从 X500 证书中获取逗号分隔的可分辨名称。 |
Oid |
获取或设置 AsnEncodedData 对象的 Oid 值。 (继承自 AsnEncodedData) |
RawData |
获取或设置字节数组中表示的抽象语法表示法一(ASN.1)编码的数据。 (继承自 AsnEncodedData) |
方法
CopyFrom(AsnEncodedData) |
从 AsnEncodedData 对象复制信息。 (继承自 AsnEncodedData) |
Decode(X500DistinguishedNameFlags) |
使用 |
EnumerateRelativeDistinguishedNames(Boolean) |
循环访问此可分辨名称值内的 RelativeDistinguishedName 值。 |
Equals(Object) |
确定指定的对象是否等于当前对象。 (继承自 Object) |
Format(Boolean) |
返回 X500 可分辨名称的格式版本,用于打印或输出到文本窗口或控制台。 |
GetHashCode() |
用作默认哈希函数。 (继承自 Object) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
MemberwiseClone() |
创建当前 Object的浅表副本。 (继承自 Object) |
ToString() |
返回一个表示当前对象的字符串。 (继承自 Object) |