title: How to verify that a pdf file contains a valid digital signature?
body: <p>I have a pdf that has been digitally signed and I would like to check if:</p>
  
  <p>1) the pdf contains a signature</p>
  
  <p>2) if the signature is valid</p>
  
  <p>I have already tried some code using the iTextSharp library, but without success. Place one of the solutions I've tried, but without success. Particularly when I check on names.Count, it succeeds and immediately returns false. I am attaching a screen to read AcroFields, I don't know if it can help to understand the problem. I can't get out of it.</p>
  
  <p><a href="https://i.stack.imgur.com/IL15C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/IL15C.png?s=256" alt="enter image description here"></a> <a href="https://i.stack.imgur.com/MiIv0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MiIv0.png?s=256" alt="enter image description here"></a></p>
  
  <pre><code>public static bool ValidateFileSignatures(byte[] file)
  {
  
      PdfReader reader = new PdfReader(file);
  
      AcroFields af = reader.AcroFields;
      var names = af.GetSignatureNames();
      if (names.Count == 0)
          return false; // no signatures
  
      foreach (string name in names)
      {
          if (!af.SignatureCoversWholeDocument(name))
          {
              return false;
          }
  
          PdfPKCS7 pk = af.VerifySignature(name);
  
  
          if (!pk.Verify())
          {
              return false;
          }
      }
  
      return true;
  }
  </code></pre>
  
  <p>The sample PDF can be found <a href="https://www.dropbox.com/sh/g95ou9lbf4kcqg7/AADgmkv1YpOri3S3g2YIUZa2a?dl=0" rel="nofollow noreferrer">here</a></p>
  
  <p>I also found another solution that uses the Pknet library, but I couldn't find the NuGet package. Any solution or suggestion is welcome. Thank you</p>