Hi,
Is there somewhere I can privately upload an example document?
Here is the code sample of how I am signing:
var returnStream = new MemoryStream();
using (var sfDocument = new PdfLoadedDocument(stream))
{
//Creates a digital signature
var signature = new PdfSignature(sfDocument, sfDocument.Pages[sfDocument.Pages.Count - 1], null, signedName);
signature.ContactInfo = contactInfo;
signature.Reason = reason;
signature.LocationInfo = location;
signature.SignedName = signedName;
signature.Certificated = true;
signature.DocumentPermissions = PdfCertificationFlags.AllowFormFill;
// Add long term validity
signature.CreateLongTermValidity(certchain);
signature.ComputeHash += (o, e) =>
{
//Get the document bytes.
byte[] documentBytes = e.Data;
e.SignedData = SignViaHSM(certchain.Last(), documentBytes);
};
// Save out the result
sfDocument.Save(returnStream);
}
return returnStream;
}
This returns a valid PDF according to Adobe reader.
When I then try to validate like this it says invalid:
var doc = new PdfLoadedDocument(stream);
var form = doc.Form;
List<PdfSignatureValidationResult> results = null;
//Validate all the digital signatures present in the PDF document.
bool isvalid = form.Fields.ValidateSignatures(out results); //<------- isValid = false, "There are errors in the formatting or information contained in the signature."
And if I try to include the root certificates it throws a null reference exception:
bool isvalid = form.Fields.ValidateSignatures(collection, out results); //<--- NullReferenceException