Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6353795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:28:21+00:00 2026-05-24T22:28:21+00:00

I have a PKCS #7, signed, .p7b file which contains an X509 SSL certificate

  • 0

I have a PKCS #7, signed, .p7b file which contains an X509 SSL certificate and the intermediate and root CA certs it was signed with. I need to use C# to parse the .p7b file, pull out the SSL certificate, and pull some values off of it (expiry date, DN, etc).

I’ve tried reading it as an X509 certificate like so:

//certContent is a byte array with the p7b file contents
X509Certificate2 cert = new X509Certificate2(certContent);

That works fine with a regular .cer certificate, but throws a CryptographicException when used with a .p7b certificate. This is because the .p7b contains the entire certificate chain.

I’ve also tried parsing it as a SignedCms object, then iterating through the certificate chain and pulling out my SSL certificate:

SignedCms certContainer = new SignedCms();
certContainer.Decode(certContent);
foreach(X509Certificate2 cert in certConatiner.Certificates)
{
     ...
}

However that throws an exception on Decode saying ASN1 bad tag value met. After some searching, I believe that is because I do not have the private key which was used to create the certificate and/or sign the certificate.

Does anyone know how I can parse this .p7b certificate chain using C#?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:28:21+00:00Added an answer on May 24, 2026 at 10:28 pm

    Well, I’m an idiot. I opened up the .p7b file and realized it was just base64 on the inside. I pulled out the base64, decoded that, then parsed that as a signed CMS and all is well.

    String content = Encoding.UTF8.GetString(certContent);
    String base64Content = content.Replace("-----BEGIN CERTIFICATE-----", "").Replace("-----END CERTIFICATE-----", "").Replace("\r", "").Replace("\n", "");
    byte[] decodedContent = Convert.FromBase64String(base64Content);
    SignedCms certContainer = new SignedCms();
    certContainer.Decode(decodedContent);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been issued a PKCS#12 certificate to be used for accessing a simple
I have an application which is making use of the RSACryptoServiceProvider to decrypt some
I have an .pxf (AFAIK PKCS#12) certificate. How can I confirm a given password
I seem to have misunderstanding here. I need to implement public/private key encryption (PKCS)
I have a PKCS#5 encrypted PKCS#8 RSA private key stored in a disk file
Backstory: I have a PKCS#12 (p12) certificate with a symmetric cipher (password) that I
I am trying to use BouncyCastle to encrypt a file using the PKCS 7
We have a valid PKCS#10 Certificate Request generated on the Client using CertEnroll. Now
I have a tcp server which uses certificates for ssl/tls and licensing. For the
I have a file with the '.pfx' extension and a password to this certificate.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.