Retrieve digital certificate information

6

I'm working with digitally signed PKCS # 7 PDF files. I have searched the internet and can not find a way to retrieve subscriber information.

Using the SignedCms class I can even get some information when I do the decode of the file, within the Certificates attribute, but I can not manipulate them, for example, get the subscriber name and put it in string .

Has anyone worked with this?

    
asked by anonymous 06.05.2015 / 20:59

1 answer

3

As you have quoted, I will consider that you have access to the Certificates of class SignedCms .

This Certificates property represents a collection of X509Certificate2

The X509Certificate2 class is the class that represents the certificate information. In this case the certificate that made the signature.

In this class you will find the SubjectName which is the property that contains the subscriber name.

Then you can give a foreach in the Certificates property, an example:

using System;
using System.Security.Cryptography.Pkcs;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            SignedCms signedCms = new SignedCms();
            foreach (var certificado in signedCms.Certificates)
            {
                Console.WriteLine(certificado.SubjectName.Name);
            }

        }
    }
}

Or you can be more straightforward by extracting the certificate from the p7s file:

using System;
using System.Security.Cryptography.X509Certificates;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            X509Certificate2 cert = new X509Certificate2(@"C:\Temp\MeuPDFAssinado.p7s");
            Console.WriteLine(cert.SubjectName.Name);
            Console.ReadKey();        
        }
    }
}
    
07.08.2015 / 16:13