Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create X509Chain with more than one element?

Tags:

c#

.net

I simply want to use a X509Chain but I don't know how to create it. I have certificates but I don't know how to put in the chain more than one certificate. I looked in MSDN and there I saw a sample that shows to creat the X509Chain like that:

X509Chain ch=new X509Chain();
ch.Build(X509Certificate2);

so I created one X509Certificate2 and inserted it to the Build(), but I don't know how can I add the other sub certificates of my chain.

like image 801
user1016179 Avatar asked Dec 18 '25 22:12

user1016179


1 Answers

X509Chain.Build() method expects to get one leaf certificate to build up from it all the chain. The build method looks for the certificates chain on the local computer certificate store, if you want to build chain from certificates that weren't installed on the computer store, you can generate your own store by:

X509Chain.ChainPolicy.ExtraStore.Add(X509Certificate2 RootCertificate);

and then perform:

X509Chain.Build(LeafCertificate);

to build the chain.

like image 101
RRR Avatar answered Dec 21 '25 12:12

RRR