Verification performs two independent checks. First the signature itself is verified cryptographically: if the document was altered after signing, the result is not valid regardless of any other option. Then any criteria you set on DigitalVerifyOptions - certificate, subject name, issuer name, signing time, reason, contact or location - are matched. Both must pass for IsValid to be true. For PDF documents the cryptographic check was added in GroupDocs.Signature for .NET 26.9; earlier versions compared only the criteria.
Here are the steps to verify Digital signature within the document with GroupDocs.Signature:
Create new instance ofΒ SignatureΒ class and pass source document path as a constructor parameter.
Instantiate theΒ DigitalVerifyOptionsΒ object according to your requirements and specify verification options
This example shows how to verify Digital signature in the document.
using(Signaturesignature=newSignature("sample.pdf")){DigitalVerifyOptionsoptions=newDigitalVerifyOptions("certificate.pfx"){Password="1234567890",// the subject of the signing certificate must contain this textSubjectName="John Smith",// the signing reason stored in the PDF signature must be equal to this textReason="Approved"};// verify document signaturesVerificationResultresult=signature.Verify(options);if(result.IsValid){Console.WriteLine("\nDocument was verified successfully!");}else{Console.WriteLine("\nDocument failed verification process.");}}
Verification criteria by document format
Not every property of DigitalVerifyOptions applies to every document format. A property that does not apply is ignored, so it can neither reject nor accept a signature. For example, Comments has no effect on a PDF document, because PDF signatures have no comment field: use Reason instead.
Property
PDF
Word Processing
Spreadsheet
Presentation
Certificate (serial number and thumbprint)
yes
yes
yes
yes
SubjectName, IssuerName
yes
yes
no
no
SignDateTimeFrom, SignDateTimeTo
yes
yes
yes
yes
Reason, Contact, Location
yes
no
no
no
Comments
no
yes
yes
yes
SubjectName and IssuerName match when the subject or issuer of the signing certificate contains the value, case-sensitive. They apply to PDF documents starting with GroupDocs.Signature for .NET 26.9; earlier versions ignored them there.
Advanced Usage Topics
To learn more about document eSign features, please refer to theΒ advanced usage section.
More resources
GitHub Examples
You may easily run the code above and see the feature in action in ourΒ GitHub examples: