I am having a problem with the NuGet package Spire.PDF. Namely, signatureOne.VerifySignature() throws an exception for a valid signed document.
I am using the latest version of Spire.PDF NuGet package (version 3.9.604, publish date 1/19/2018).
This is the code I used to validate it:
- Code: Select all
string path = @"D:\Pact(3).pdf";
var signatures = new List<PdfSignature>();
bool signitureIsValid;
using (var doc = new PdfDocument(path))
{
var form = (PdfFormWidget) doc.Form;
for (int i = 0; i < form.FieldsWidget.Count; ++i)
{
if (form.FieldsWidget[i] is PdfSignatureFieldWidget field && field.Signature != null)
{
PdfSignature signature = field.Signature;
signatures.Add(signature);
}
}
try
{
PdfSignature signatureOne = signatures[0];
signitureIsValid = signatureOne.VerifySignature(); //Exception thrown for valid signature ! Why ?!
}
catch (Exception ex)
{
Console.WriteLine(ex);
Console.WriteLine(ex.StackTrace);
Debug.WriteLine(ex);
}
}
The exception thrown is not very intelligible or helpful, it just states that signature 'sirnature1' failed to validate without giving any clue as to why this is happening...
Here is some of the output text of the exception:
System.ArgumentException: Signature 'Signature1' failed to verified.
at spr?.?(String A_0)
at Spire.Pdf.Security.PdfSignature.VerifySignature()
at PDFTest.Program.Main(String[] args) in ....
Could you please give me some ways of troubleshooting this problem ?
Respectfully,
Zoran