Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve digital signature information (name, date, ...) with ItextSharp

I have a PDF which has been signed by 2 people (by Eid).

I'm trying to retrieve this information but I'm unable so far.

This is what I have so far:

namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                string workingFolder = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                string inputFile = Path.Combine(workingFolder, "Tax Return.pdf");            

                PdfReader reader = new PdfReader(inputFile);

                Console.ReadLine();
            }
        }
    }

If I inspect 'reader' during runtime I can see that AcroForm has 2 Fields that point to the signatures but I'm unable to see any specific information about these signatures.

like image 267
Fbo Avatar asked Mar 22 '12 13:03

Fbo


1 Answers

Short example:

StringBuilder sb = new StringBuilder();
PdfReader reader = new PdfReader(pdf);
AcroFields af = reader.AcroFields;
ArrayList  names = af.GetSignatureNames();
for (int i = 0; i < names.Count; ++i) {
  String name = (string)names[i];
  PdfPKCS7 pk = af.VerifySignature(name);
  sb.AppendFormat("Signature field name: {0}\n", name);
  sb.AppendFormat("Signature signer name: {0}\n", pk.SignName);
  sb.AppendFormat("Signature date: {0}\n", pk.SignDate);
  sb.AppendFormat("Signature country: {0}\n",  
    PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("C")
  );
  sb.AppendFormat("Signature organization: {0}\n",  
    PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("O")
  );
  sb.AppendFormat("Signature unit: {0}\n",  
    PdfPKCS7.GetSubjectFields(pk.SigningCertificate).GetField("OU")
  );
}
like image 140
kuujinbo Avatar answered Nov 04 '22 03:11

kuujinbo