Skip to content
DemoSampleAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub
Android Guides Verify digital signatures

Verify Digital Signatures ​

CPDFSignatureValidator provides document-level and field-level reports for signature integrity, coverage, document permissions, certificate chains, timestamps, and revocation materials. Existing boolean methods such as CPDFSignature.verify() remain available.

Validate a Signed File ​

Here, document is the open signed output document. trustedCertPath is a PEM bundle of trusted roots or an OpenSSL-style certificate directory. Run validation on a background thread and keep the document open throughout the operation.

java
import com.compdfkit.core.signature.CPDFSignatureValidationOptions;
import com.compdfkit.core.signature.CPDFSignatureValidationResult;
import com.compdfkit.core.signature.CPDFSignatureValidationReport;
import com.compdfkit.core.signature.CPDFSignatureValidator;

CPDFSignatureValidationOptions options = new CPDFSignatureValidationOptions()
    .setTrustedCertPath(trustedCertPath)
    .setCheckTimestamp(true)
    .setCheckRevocation(true);

CPDFSignatureValidationResult result = CPDFSignatureValidator.validate(document, options);
if (result != null && result.isSuccess()) {
    for (CPDFSignatureValidationReport report : result.getReports()) {
        String fieldName = report.getFieldName();
        // Inspect report.getOverallStatus() and the checks in report.getItems().
    }
} else {
    // Validation did not execute successfully. Inspect errors and warnings if result is non-null.
}
kotlin
val options = CPDFSignatureValidationOptions()
    .setTrustedCertPath(trustedCertPath)
    .setCheckTimestamp(true)
    .setCheckRevocation(true)

val result = CPDFSignatureValidator.validate(document, options)
if (result != null && result.isSuccess) {
    for (report in result.reports) {
        val fieldName = report.fieldName
        // Inspect report.overallStatus and the checks in report.items.
    }
} else {
    // Handle execution failure and inspect errors and warnings.
}

You can also call validate(pdfPath, options) for a file path, or use options.setFieldName(fieldName) to restrict validation to one field. An empty name validates all signatures.

For path-loaded documents, signature bytes are read from the file; Uri-loaded documents use their file access handle. Open and validate the actual signed output, rather than treating unsaved edits as the signed file.

Configure Checks ​

CheckConfiguration methodDefault
Signed-byte integritysetCheckIntegrity()true
ByteRange coveragesetCheckCoverage()true
DocMDP/FieldMDP permissions for later revisionssetCheckDocumentPermissions()true
Certificate chainsetCheckCertificateChain()true
TimestampsetCheckTimestamp()true
Revocation and LTVsetCheckRevocation()false

Android provides no default OpenSSL trust store for this validator. Configure trusted certificates for chain and TSA trust checks. Enable setCheckRevocation(true) for LTV assessment; with it disabled, a false result from isLtvEnabled() does not prove that LTV materials are missing.

Validation reads OCSP/CRL evidence from the document's DSS and does not fetch missing materials online. See Long-Term Validation and PAdES Signing to add materials.

Interpret Results ​

result.isSuccess() only indicates that validation executed successfully, not that every signature is valid. Check the report count, overall status, and individual checks:

CPDFValidationStatusMeaning
VALIDThe relevant check passed
INVALIDThe relevant check failed
INDETERMINATENo definite conclusion, for example because trust anchors or materials are missing
NOT_CHECKEDThe check is disabled or not applicable

report.getItems() provides individual checks. Use getCode(), getStatus(), and getMessage() to record reasons. result.getErrors() and getWarnings() provide run-level errors and warnings.

report.hasEmbeddedTimestamp() reads timestamp-related flags and does not establish timestamp trust on its own. report.isLtvEnabled() depends on the checks enabled; display it together with the complete signature report.