API referenceDigital Signatures

pdfVerifySignature

Verify a digital signature of the currently open import

C
SI32 __stdcall pdfVerifySignature(void* ISignature);
Delphi
function pdfVerifySignature(const ISignature: Pointer): Integer; stdcall;

Purpose. Verify a digital signature of the currently open import file: does the detached CMS signature match the /ByteRange-covered bytes, and do those ranges still cover the whole file?

Description. ISignature is addressed exactly like pdfGetSigDict: pass the per-signature handle from TPDFFieldEx.ISignature (filled by pdfGetFieldEx for every SIGNED signature field) to verify THAT signature, or pass the document handle to verify the document's first signed field. The check re-reads the import file from disk, validates the /ByteRange layout, and verifies the detached CMS over the two covered ranges with the platform cryptography provider. Certificate chain and trust validation are deliberately out of scope — this call answers "is the document unmodified under this signature", not "do you trust the signer".

The result is a bit mask, so a caller can distinguish "checked and failed" from "could not be checked":

BitValueMeaning
01The detached CMS signature VERIFIES over the covered bytes.
12The byte ranges cover the whole file (only trailing PDF whitespace after them — nothing was appended since signing).
24The CMS check was actually performed. Without this bit, the absence of bit 0 means "not checked" (unsupported SubFilter or platform), never "forged".

A fully intact signature on an unmodified file answers 7. A file modified after signing typically answers 6 (ranges fine, CMS check performed, signature no longer matches). On a multi-signature file the EARLIER signature of an incrementally re-signed document answers 5 — still valid, but the file grew past its ranges, which is exactly what an incremental update does. Detached SubFilters (adbe.pkcs7.detached, ETSI.CAdES.detached) are verified in this release.

Parameters.

ParameterDescription
ISignatureA per-signature handle (TPDFFieldEx.ISignature) or the document handle (first signed field).

Return value. -1 on hard error (no import file, no matching signed field, unreadable file, malformed /ByteRange); otherwise the flag mask described above.

See also. pdfGetSigDict, pdfGetFieldEx, pdfSetSigTimeStampUrl.

C# (P/Invoke)

wrappers/dotnet/LumasPdf.cs
public static extern int pdfVerifySignature(IntPtr ISignature);
Area
Digital Signatures
Category

Core

Exported names

pdfVerifySignature

String variants

The …A form takes UTF-8, …W takes UTF-16; a bare name aliases the ANSI form.

See working code

Worked examples — complete programs in ten languages.