-1

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.

Dante
  • 221
  • 1
  • 3
  • 14
  • 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 02 '18 at 19:45
  • Possible duplicate of [Extracting individual .cer certificate from a .p7b file in java](https://stackoverflow.com/questions/19244860/extracting-individual-cer-certificate-from-a-p7b-file-in-java) – Robert Aug 06 '18 at 12:03

1 Answers1

0

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;