X500DistinguishedName 建構函式
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
初始化 X500DistinguishedName 類別的新執行個體。
多載
X500DistinguishedName(Byte[]) |
使用來自指定位元組陣列的資訊,初始化 X500DistinguishedName 類別的新執行個體。 |
X500DistinguishedName(ReadOnlySpan<Byte>) |
使用來自所提供資料的資訊,將 X500DistinguishedName 類別的新執行個體初始化。 |
X500DistinguishedName(AsnEncodedData) |
使用指定的 AsnEncodedData 物件,初始化 X500DistinguishedName 類別的新執行個體。 |
X500DistinguishedName(X500DistinguishedName) |
使用指定的 X500DistinguishedName 物件,初始化 X500DistinguishedName 類別的新執行個體。 |
X500DistinguishedName(String) |
使用來自指定字串的資訊,初始化 X500DistinguishedName 類別的新執行個體。 |
X500DistinguishedName(String, X500DistinguishedNameFlags) |
使用指定的字串和 X500DistinguishedName 旗標,初始化 X500DistinguishedNameFlags 類別的新執行個體。 |
X500DistinguishedName(Byte[])
使用來自指定位元組陣列的資訊,初始化 X500DistinguishedName 類別的新執行個體。
public:
X500DistinguishedName(cli::array <System::Byte> ^ encodedDistinguishedName);
public X500DistinguishedName (byte[] encodedDistinguishedName);
new System.Security.Cryptography.X509Certificates.X500DistinguishedName : byte[] -> System.Security.Cryptography.X509Certificates.X500DistinguishedName
Public Sub New (encodedDistinguishedName As Byte())
參數
- encodedDistinguishedName
- Byte[]
包含辨別名稱資訊的位元組陣列。
範例
下列程式碼範例示範如何使用 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
備註
X500DistinguishedName 類別繼承自 AsnEncodedData 類別。
適用於
X500DistinguishedName(ReadOnlySpan<Byte>)
使用來自所提供資料的資訊,將 X500DistinguishedName 類別的新執行個體初始化。
public:
X500DistinguishedName(ReadOnlySpan<System::Byte> encodedDistinguishedName);
public X500DistinguishedName (ReadOnlySpan<byte> encodedDistinguishedName);
new System.Security.Cryptography.X509Certificates.X500DistinguishedName : ReadOnlySpan<byte> -> System.Security.Cryptography.X509Certificates.X500DistinguishedName
Public Sub New (encodedDistinguishedName As ReadOnlySpan(Of Byte))
參數
- encodedDistinguishedName
- ReadOnlySpan<Byte>
編碼的辨別名稱。
適用於
X500DistinguishedName(AsnEncodedData)
使用指定的 AsnEncodedData 物件,初始化 X500DistinguishedName 類別的新執行個體。
public:
X500DistinguishedName(System::Security::Cryptography::AsnEncodedData ^ encodedDistinguishedName);
public X500DistinguishedName (System.Security.Cryptography.AsnEncodedData encodedDistinguishedName);
new System.Security.Cryptography.X509Certificates.X500DistinguishedName : System.Security.Cryptography.AsnEncodedData -> System.Security.Cryptography.X509Certificates.X500DistinguishedName
Public Sub New (encodedDistinguishedName As AsnEncodedData)
參數
- encodedDistinguishedName
- AsnEncodedData
表示辨別名稱的 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
備註
X500DistinguishedName 類別繼承自 AsnEncodedData 類別。
適用於
X500DistinguishedName(X500DistinguishedName)
使用指定的 X500DistinguishedName 物件,初始化 X500DistinguishedName 類別的新執行個體。
public:
X500DistinguishedName(System::Security::Cryptography::X509Certificates::X500DistinguishedName ^ distinguishedName);
public X500DistinguishedName (System.Security.Cryptography.X509Certificates.X500DistinguishedName distinguishedName);
new System.Security.Cryptography.X509Certificates.X500DistinguishedName : System.Security.Cryptography.X509Certificates.X500DistinguishedName -> System.Security.Cryptography.X509Certificates.X500DistinguishedName
Public Sub New (distinguishedName As X500DistinguishedName)
參數
- distinguishedName
- 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
備註
這個建構函式會建立指定 X500DistinguishedName 對象的複本。 X500DistinguishedName 類別繼承自 AsnEncodedData 類別。
適用於
X500DistinguishedName(String)
使用來自指定字串的資訊,初始化 X500DistinguishedName 類別的新執行個體。
public:
X500DistinguishedName(System::String ^ distinguishedName);
public X500DistinguishedName (string distinguishedName);
new System.Security.Cryptography.X509Certificates.X500DistinguishedName : string -> System.Security.Cryptography.X509Certificates.X500DistinguishedName
Public Sub New (distinguishedName As String)
參數
- distinguishedName
- String
表示辨別名稱的字串。
範例
下列程式碼範例示範如何使用 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
備註
X500DistinguishedName 類別繼承自 AsnEncodedData 類別。
適用於
X500DistinguishedName(String, X500DistinguishedNameFlags)
使用指定的字串和 X500DistinguishedName 旗標,初始化 X500DistinguishedNameFlags 類別的新執行個體。
public:
X500DistinguishedName(System::String ^ distinguishedName, System::Security::Cryptography::X509Certificates::X500DistinguishedNameFlags flag);
public X500DistinguishedName (string distinguishedName, System.Security.Cryptography.X509Certificates.X500DistinguishedNameFlags flag);
new System.Security.Cryptography.X509Certificates.X500DistinguishedName : string * System.Security.Cryptography.X509Certificates.X500DistinguishedNameFlags -> System.Security.Cryptography.X509Certificates.X500DistinguishedName
Public Sub New (distinguishedName As String, flag As X500DistinguishedNameFlags)
參數
- distinguishedName
- String
表示辨別名稱的字串。
列舉值的位元組合,這些值會指定辨別名稱的特性。
範例
下列程式碼範例示範如何使用 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
備註
X500DistinguishedName 類別繼承自 AsnEncodedData 類別。