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) |
使用 |
EnumerateRelativeDistinguishedNames(Boolean) |
逐一查看這個辨別名稱值內的 RelativeDistinguishedName 值。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
Format(Boolean) |
傳回 X500 辨別名稱的格式化版本,用於列印或輸出至文字視窗或主控台 (Console)。 |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應