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.dll>
#using <system.security.dll>
using namespace System;
using namespace System::Security::Cryptography;
using namespace System::Security::Permissions;
using namespace System::IO;
using namespace System::Security::Cryptography::X509Certificates;
int main()
{
try
{
X509Store ^ store = gcnew X509Store( "MY",StoreLocation::CurrentUser );
store->Open( static_cast<OpenFlags>(OpenFlags::ReadOnly | OpenFlags::OpenExistingOnly) );
X509Certificate2Collection ^ collection = dynamic_cast<X509Certificate2Collection^>(store->Certificates);
X509Certificate2Collection ^ fcollection = dynamic_cast<X509Certificate2Collection^>(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: {0}{1}", scollection->Count, Environment::NewLine );
System::Collections::IEnumerator^ myEnum = scollection->GetEnumerator();
while ( myEnum->MoveNext() )
{
X509Certificate2 ^ x509 = safe_cast<X509Certificate2 ^>(myEnum->Current);
X500DistinguishedName ^ dname = gcnew X500DistinguishedName( x509->SubjectName );
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." );
}
}
using System;
using System.Security.Cryptography;
using System.Security.Permissions;
using System.IO;
using System.Security.Cryptography.X509Certificates;
class X500Sample
{
static void Main()
{
try
{
X509Store store = new X509Store("MY", StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly | OpenFlags.OpenExistingOnly);
X509Certificate2Collection collection = (X509Certificate2Collection)store.Certificates;
X509Certificate2Collection fcollection = (X509Certificate2Collection)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: {0}{1}", scollection.Count, Environment.NewLine);
foreach (X509Certificate2 x509 in scollection)
{
X500DistinguishedName dname = new X500DistinguishedName(x509.SubjectName);
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
Imports System.Security.Permissions
Imports System.IO
Imports System.Security.Cryptography.X509Certificates
Class X500Sample
Shared 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 = CType(store.Certificates, X509Certificate2Collection)
Dim fcollection As X509Certificate2Collection = CType(collection.Find(X509FindType.FindByTimeValid, DateTime.Now, False), X509Certificate2Collection)
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)
msg = "Number of certificates: " & scollection.Count & Environment.NewLine
MsgBox(msg)
Dim x509 As X509Certificate2
For Each x509 In scollection
Dim dname As New X500DistinguishedName(x509.SubjectName)
msg = "X500DistinguishedName: " & dname.Name & Environment.NewLine
MsgBox(msg)
x509.Reset()
Next x509
store.Close()
Catch e As Exception
msg = "Error: Information could not be written out for this certificate."
MsgBox(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) |
使用由 |
Equals(Object) |
确定指定对象是否等于当前对象。 (继承自 Object) |
Format(Boolean) |
返回 X500 识别名的格式化版本,以便打印或输出到文本窗口或控制台。 |
GetHashCode() |
作为默认哈希函数。 (继承自 Object) |
GetType() |
获取当前实例的 Type。 (继承自 Object) |
MemberwiseClone() |
创建当前 Object 的浅表副本。 (继承自 Object) |
ToString() |
返回表示当前对象的字符串。 (继承自 Object) |