Get certificate Chain from P7B file

Clash Royale CLAN TAG#URR8PPP
Get certificate Chain from P7B file
How can I get the certificate chain from P7B file.
P7B file only contains the certificate and public key. I wanted to get the certificate chain and attach signature to pdf file. I am using Bouncy Castle library for this.
Any help would be appreciated.
Possible duplicate of Extracting individual .cer certificate from a .p7b file in java
– Robert
Aug 6 at 12:03
1 Answer
1
The import of a p7b file depends on the format of the file. If it is the DER format, this code should work:
List<X509Certificate> certList = new List<X509Certificate>();
var signedData = File.ReadAllBytes(filepath);
CmsSignedData s = new CmsSignedData(signedData);
IX509Store certs = s.GetCertificates("Collection");
ICollection cCol = certs.GetMatches(null);
var cEn = cCol.GetEnumerator();
while (cEn.MoveNext())
certList.Add((X509Certificate)cEn.Current);
return certList;
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
That's a rather quick error, so the file is possibly in the wrong format? We cannot tell, we don't see the file.
– Maarten Bodewes
Aug 2 at 19:45