Hi,
I’m using Aspose.Pdf.Facades.PdfFileSignature to digitally sign PDFs.
If I sign a document in the UK time zone and then open it shortly afterwards with Adobe Reader in the US Eastern time zone, the digital signature is shown as invalid with the message ‘Signature seems to be signed in future’.
Initially this appeared to be a problem with Adobe Reader, but if I alter my code to use Aspose.Pdf.Kit.PdfFileSignature, the signature is shown as valid.
I have prepared the attached PDF documents, one signed with PDF Kit and one signed with Facades. When I open them in Adobe Reader, I see the following when I right-click on the signature and choose ‘Show signature properties’:
Aspose.Pdf.Facades.PdfFileSignature:
Signing time UK time zone: 2013/05/07 09:16:06 +01’00’ Signature is VALID
Signing time US Eastern time zone: 2013/05/07 09:16:06 -04’00’ Signature is INVALID: Signature seems to be signed in future
Aspose.Pdf.Kit.PdfFileSignature:
Signing time UK time zone:2013/05/07 09:13:33 +01’00’ Signature is VALID
Signing time US Eastern time zone: 2013/05/07 04:13:33 -04’00’ Signature is VALID
With the US Eastern time zone, the time displayed is the same as the UK time zone for the Facades-generated signature, but 5 hours earlier with the Pdf.Kit-generated signature (which is correct). This means that the problem must lie with Aspose.Pdf.Facades.PdfFileSignature.
Also, I note that when signing with PDF Kit, a blue bar is visible within Adobe Reader indicating that the document is ‘Signed and all signatures are valid.’ How can I get this to be displayed with Facades.PdfFileSignature?
Finally, I found this page in the Aspose.Pdf.Facades documentation…
…but Apose.Pdf.Facades.PdfFileSignature does not have the CertificationLevel property.
Sample code for Aspose.Pdf.Facades:
private Stream AddDigitalSignature(Stream pdf, string signatureFile, string signaturePassword)
{
// Create the signer.
Aspose.Pdf.Facades.PdfFileSignature pdfSign = new Aspose.Pdf.Facades.PdfFileSignature();
pdfSign.BindPdf(pdf);
// Create the signature.
Aspose.Pdf.InteractiveFeatures.Forms.PKCS7 signature = new Aspose.Pdf.InteractiveFeatures.Forms.PKCS7(signatureFile, signaturePassword);
// Sign and save.
MemoryStream stream = new MemoryStream();
pdfSign.Sign(1, DigitalReason, DigitalContact, DigitalLocation, false, new Rectangle(), signature);
pdfSign.Save(stream);
return stream;
}
Sample code for Aspose.Pdf.Kit:
private Stream AddDigitalSignature(string pdfPath, string signatureFile, string signaturePassword)
{
Aspose.Pdf.Kit.PdfFileSignature pdfSign = new Aspose.Pdf.Kit.PdfFileSignature(pdfPath);
pdfSign.CertificationLevel = Aspose.Pdf.Kit.PdfFileSignature.CertifiedNoChangeAllowed;
Aspose.Pdf.Kit.Pkcs7Signature signature = new Aspose.Pdf.Kit.Pkcs7Signature(signatureFile, signaturePassword);
MemoryStream stream = new MemoryStream();
pdfSign.Sign(1, DigitalReason, DigitalContact, DigitalLocation, false, new Rectangle(), signature);
pdfSign.Save(stream);
return stream;
}