X509Chain.ChainElements Свойство
Определение
Важно!
Некоторые сведения относятся к предварительной версии продукта, в которую до выпуска могут быть внесены существенные изменения. Майкрософт не предоставляет никаких гарантий, явных или подразумеваемых, относительно приведенных здесь сведений.
Возвращает коллекцию X509ChainElement объектов.
public:
property System::Security::Cryptography::X509Certificates::X509ChainElementCollection ^ ChainElements { System::Security::Cryptography::X509Certificates::X509ChainElementCollection ^ get(); };
public System.Security.Cryptography.X509Certificates.X509ChainElementCollection ChainElements { get; }
member this.ChainElements : System.Security.Cryptography.X509Certificates.X509ChainElementCollection
Public ReadOnly Property ChainElements As X509ChainElementCollection
Значение свойства
Объект X509ChainElementCollection.
Примеры
В следующем примере кода показано упорядочение элементов цепочки:
using var chain = new X509Chain();
chain.Build(certificate);
// chain.ChainElements[0] is the leaf (end-entity) certificate
// chain.ChainElements[^1] is the root (trust anchor) certificate
Console.WriteLine("Certificate chain from leaf to root:");
for (int i = 0; i < chain.ChainElements.Count; i++)
{
var cert = chain.ChainElements[i].Certificate;
var role = i == 0 ? "Leaf" :
i == chain.ChainElements.Count - 1 ? "Root" : "Intermediate";
Console.WriteLine($"[{i}] {role}: {cert.Subject}");
}
В следующем примере кода открывается личное хранилище сертификатов текущего пользователя, можно выбрать сертификат, а затем записать сведения о сертификате и цепочке сертификатов в консоль. Выходные данные зависят от выбранного сертификата.
//Output chain element information.
Console.WriteLine ("Chain Element Information");
Console.WriteLine ("Number of chain elements: {0}", ch.ChainElements.Count);
Console.WriteLine ("Chain elements synchronized? {0} {1}", ch.ChainElements.IsSynchronized, Environment.NewLine);
foreach (X509ChainElement element in ch.ChainElements)
{
Console.WriteLine ("Element issuer name: {0}", element.Certificate.Issuer);
Console.WriteLine ("Element certificate valid until: {0}", element.Certificate.NotAfter);
Console.WriteLine ("Element certificate is valid: {0}", element.Certificate.Verify ());
Console.WriteLine ("Element error status length: {0}", element.ChainElementStatus.Length);
Console.WriteLine ("Element information: {0}", element.Information);
Console.WriteLine ("Number of element extensions: {0}{1}", element.Certificate.Extensions.Count, Environment.NewLine);
if (ch.ChainStatus.Length > 1)
{
for (int index = 0; index < element.ChainElementStatus.Length; index++)
{
Console.WriteLine (element.ChainElementStatus[index].Status);
Console.WriteLine (element.ChainElementStatus[index].StatusInformation);
}
}
}
store.Close();
'Output chain element information.
Console.WriteLine("Chain Element Information")
Console.WriteLine("Number of chain elements: {0}", ch.ChainElements.Count)
Console.WriteLine("Chain elements synchronized? {0} {1}", ch.ChainElements.IsSynchronized, Environment.NewLine)
Dim element As X509ChainElement
For Each element In ch.ChainElements
Console.WriteLine("Element issuer name: {0}", element.Certificate.Issuer)
Console.WriteLine("Element certificate valid until: {0}", element.Certificate.NotAfter)
Console.WriteLine("Element certificate is valid: {0}", element.Certificate.Verify())
Console.WriteLine("Element error status length: {0}", element.ChainElementStatus.Length)
Console.WriteLine("Element information: {0}", element.Information)
Console.WriteLine("Number of element extensions: {0}{1}", element.Certificate.Extensions.Count, Environment.NewLine)
If ch.ChainStatus.Length > 1 Then
Dim index As Integer
For index = 0 To element.ChainElementStatus.Length
Console.WriteLine(element.ChainElementStatus(index).Status)
Console.WriteLine(element.ChainElementStatus(index).StatusInformation)
Next index
End If
Next element
store.Close()
Комментарии
Каждый X509ChainElement объект представляет элемент в цепочке, созданной во время вызова Build метода.
Элемент цепочки состоит из X509Certificate2 объекта, X509ChainStatus структуры и дополнительной информационной строки.
Коллекция ChainElements упорядочивается из конечного сертификата (конечной) сущности по индексу 0 через все промежуточные сертификаты в привязку доверия (корневой сертификат) по окончательному индексу. Это упорядочивание согласовано на всех платформах.