Retrieve information from digital certificate

Asked

Viewed 1,437 times

6

I’m working with digitally signed PKCS#7 PDF files. I searched the Internet and I can’t find a way to retrieve subscriber information.

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

Someone has worked with that?

1 answer

3

As you mentioned, I will consider that you have access to the property Certificates class Signedcms.

This Certificates property represents a Collection of X509certificate2

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

In this class you will find the property Subjectname which is the property that contains the subscriber’s name.

Then you can give a foreach on 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 direct 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();        
        }
    }
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.