Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit20a51c9

Browse files
authored
Document ordering guarantee for X509Chain.ChainElements collection (#11475)
1 parent1bab578 commit20a51c9

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
usingSystem;
2+
usingSystem.Security.Cryptography.X509Certificates;
3+
4+
publicclassChainElementsOrdering
5+
{
6+
publicstaticvoidDemonstrateChainElementsOrdering(X509Certificate2certificate)
7+
{
8+
//<SNIPPET6>
9+
usingvarchain=newX509Chain();
10+
chain.Build(certificate);
11+
12+
// chain.ChainElements[0] is the leaf (end-entity) certificate
13+
// chain.ChainElements[^1] is the root (trust anchor) certificate
14+
15+
Console.WriteLine("Certificate chain from leaf to root:");
16+
for(inti=0;i<chain.ChainElements.Count;i++)
17+
{
18+
varcert=chain.ChainElements[i].Certificate;
19+
varrole=i==0?"Leaf":
20+
i==chain.ChainElements.Count-1?"Root":"Intermediate";
21+
Console.WriteLine($"[{i}]{role}:{cert.Subject}");
22+
}
23+
//</SNIPPET6>
24+
}
25+
}

‎xml/System.Security.Cryptography.X509Certificates/X509Chain.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,13 @@
464464
465465
A chain element consists of an <xref:System.Security.Cryptography.X509Certificates.X509Certificate2> object, an <xref:System.Security.Cryptography.X509Certificates.X509ChainStatus> structure, and an extra information string.
466466
467-
467+
The `ChainElements` collection is ordered from the end-entity (leaf) certificate at index 0, through any intermediate certificates, to the trust anchor (root certificate) at the final index. This ordering is consistent across all platforms.
468468
469469
## Examples
470+
The following code example demonstrates the ordering of chain elements:
471+
472+
:::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography.X509Certificates/X509Chain/Overview/chainelements-ordering.cs" id="Snippet6":::
473+
470474
The following code example opens the current user's personal certificate store, allows you to select a certificate, then writes certificate and certificate chain information to the console. The output depends on the certificate you select.
471475
472476
:::code language="csharp" source="~/snippets/csharp/System.Security.Cryptography.X509Certificates/X509Chain/Overview/x509chaintest.cs" id="Snippet4":::

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp