Add Long Term Validation (LTV) data to an existing signature

Long-term validation refers to the process of verifying the authenticity and integrity of a digitally signed PDF document over an extended period of time. This involves checking the validity of the digital signature, the certificate used to sign the document, and any associated time-stamping or revocation information. Long-term validation is important to ensure that a document remains valid and trustworthy, even if the certificate used to sign it expires or is revoked. This can be accomplished through the use of a trusted third-party validation service or by maintaining a local copy of the certificate’s revocation list.

// Add Long Term Validation (LTV) data to an existing signature
using (FileStream fs = new FileStream("signed_document.pdf", FileMode.Open, FileAccess.Read))
{
   Document document = new Document(fs);
	  
   SignatureField signatureField = document.Fields["name_of_signature_field"] as SignatureField;
	  
   // load the data to fill up the list of certificates, certificate revocation lists, and certificate status protocols
   List<byte[]> certificates = new List<byte[]>(new []
   {
      File.ReadAllBytes("cert_0.dat"),
      File.ReadAllBytes("cert_1.dat"),
      File.ReadAllBytes("cert_2.dat"),
      File.ReadAllBytes("cert_3.dat")
   });

   List<byte[]> oCSPs = new List<byte[]>(
      File.ReadAllBytes("ocsp_1.dat")
   );

   List<byte[]> cRLs = new List<byte[]>(new []
   {
      File.ReadAllBytes("CRL_0.dat"),
      File.ReadAllBytes("CRL_1.dat"),
      File.ReadAllBytes("CRL_2.dat")
   });
	  
   signatureField.AddValidationInformation(certificates, oCSPs, cRLs); // add the LTV data

   using (FileStream outFs = new FileStream("ltv_enabled.pdf", FileMode.Create, FileAccess.Write))
   {
      document.Write(outFs, DocumentWriteMode.AppendUpdate); 
      // Note: it is important to use the AppendUpdate mode, otherwise the signature becomes invalid
   }
}