How can I parse .p7s file for Signer

0 votes
asked Jun 12 by tomB (230 points)

How can I parse the digital signature (.p7s) so I can get information like:
Subject, From, Signed by, Validity, etc..?

commented Jun 13 by Lukas Matyska (39,480 points)
Can you please send us example of your .p7s file to support@rebex.net?
The .p7s is typically attached to original message and it contains typically signature only (it doesn't contain Subject, From, etc.)
Very probably, you need to use classes from https://www.rebex.net/secure-mail.net/ such as MailMessage, MimeMessage, MimeEntity or SignedData

2 Answers

0 votes
answered Jun 14 by tomB (230 points)
 
Best answer
   var mail = new MailMessage();
   mail.Load(@"c:\data\mail.msg");

   Console.WriteLine("Subject: {0}", mail.Subject);
   Console.WriteLine("From: {0}", mail.From);

   if (!mail.IsSigned)
   {
          Console.WriteLine("Mail is not signed.");
   }
   else
   {
          foreach (SubjectInfo signer in mail.Signers)
          {
                 Console.WriteLine("Signed by: {0}", string.Join(", ", signer.Certificate.GetMailAddresses()));
          }
          var validity = mail.ValidateSignature();
          if (validity.Valid)
          {
                 Console.WriteLine("Signature is valid.");
          }
          else
          {
                 Console.WriteLine("Signature is not valid: {0}", validity.Status);
                 Console.WriteLine("Certificate validation status: {0}", validity.CertificateValidationStatus);
          }
   }
0 votes
answered Jun 13 by tomB (230 points)

If you view a Digital Signature in Microsoft Outlook it explicitly has:

Digital Signature:
Subject:
From:
Signed By:
etc...
I will send you a picture of what I am talking about.

...