A PDF document can be signed with a digital signature, allowing you to detect and prevent unauthorized changes to a document, as well as authenticate the signer. Also, digital signatures allow you to define permissions for changes that are to be permitted, such as adding annotations or filling in and signing forms.
There are three types of signatures in PDF: certification signatures, approval signatures, and usage rights signature.
ImageGear makes working with signatures simple. It allows for both signing and verification. After signing and saving a document, it will contain the signature(s) inside the file. After loading a signed PDF document, its signatures may be verified and the result will indicate whether the document was changed after signing and whether the signatures can be authenticated.
Certification and approval signatures are associated with a SignatureField through the field's Signature property. You can assign a signature to this property to prepare the actual signing or read it for verification purposes. If the field has not been signed, the Signature property is null.
A signature handler is used to specify the algorithm that is used to encode the signature. ImageGear provides a readily available implementation of the most common type of algorithm: PKCS7SignatureHandler. This implementation uses the PKCS#7 detached method (SubFilter adbe.pkcs7.detached) and takes a digital certificate from file or directly as a parameter. Although this sounds complicated, it is really easy to use (see the sample in Signing a Document below).
Signing a document has the following restrictions:
To sign a PDF document:
The following example illustrates the functionality of signing a PDF document with an approval signature.
Before verifying signatures, you need to tell ImageGear.NET which certificates are trusted by the user via the ImGearPDF.TrustedCertificates property. Because certificate validity and document integrity are checked, if the certificate used to sign the PDF is not trusted, an error will occur upon verification.
Verify signatures in a document by using the ImGearPDFDocument.VerifySignatures method. This method attempts to verify all signatures present in the document, and returns either SignatureVerificatonResult.OK or the result for the first signature that fails verification.
To verify each signature separately, you can loop through all of the signatures listed in ImGearPDFDocument.Signatures. This is illustrated in the example below.