Digital Signatures

Digital Signatures in PDF

PDF digital signatures use cryptographic certificates to certify document authenticity and detect tampering. Signatures are embedded in signature fields within the document.

PdfFileSignature

PdfFileSignature provides operations for signing and verifying signature fields in an existing PDF document:

try (PdfFileSignature sig = new PdfFileSignature("input.pdf")) {
    sig.sign(1, certificate, privateKey, chain, null, new DocMDPSignature(doc, DocMDPAccessPermissions.FillingInForms));
    sig.save("signed.pdf");
}

Verification checks whether the signature covers the expected byte range and whether the signing certificate is valid.

PdfSigner

PdfSigner provides the high-level signing workflow combining signature field creation, PKCS#7 container generation, and byte range calculation.

PKCS7SignedData

PKCS7SignedData.createDetached() creates a detached CMS signature container for embedding in the PDF signature dictionary. See PKCS#7 for details.

Signature Validation

After signing, signatures can be enumerated via PdfFileSignature.getSignNames() and verified by checking the signature validity status.

See Also