How to get digital signature information (name, date, ...) using ItextSharp

I have a PDF that was signed by two people (from Eid).

I am trying to get this information, but I cannot yet.

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 check the "reader" at runtime, I see that the AcroForm has 2 fields that indicate the signatures, but I don't see any specific information about those signatures.

+3


source to share


1 answer


A 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")
  );
}

      

+7


source







All Articles