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 Algorithms and certificate formats

Algorithms and Certificate Formats ​

This guide applies to ComPDF Android SDK 3.2.1. Start by checking where the private key is stored:

  • The private key is in a local file: Use local signing. Give the SDK the .p12 or .pfx file containing the certificate and its private key, along with the file password.
  • A signing service holds the private key: Use two-phase signing. Your app prepares the PDF and submits a digest. The service signs it, and your app embeds the result in the PDF.

For two-phase signing, check what the service returns. A complete CMS container includes the signature value and certificates, so the SDK can embed it as-is. A raw signature value contains only the signature bytes. Provide the certificates separately so the SDK can build the CMS container. These two paths support different algorithms. For supported Android versions, see System Requirements.

Signature Algorithms ​

Signature AlgorithmLocal SigningTwo-Phase: Complete CMSTwo-Phase: Raw SignatureSDK Validation
RSA-PKCS#1 v1.5 (RSA-2048, RSA-3072)✅ Supported✅ Supported✅ Supported✅ Supported
ECDSA P-256 (including SHA256withECDSA)✅ Supported✅ Supported✅ Supported (DER encoding)✅ Supported
ECDSA P-384✅ Supported (SHA-256)✅ Supported✅ Supported (DER encoding)✅ Supported
RSA-PSS❌ Not supported✅ Can embed❌ Not supported⚠️ Limited support; see below

Raw ECDSA signatures: Pass the signature value as a DER-encoded SEQUENCE { r, s }. If the service returns a fixed-length r‖s value (IEEE P1363), convert it to DER before embedding it in the PDF. This conversion applies to the signature value, not the certificate.

RSA-PSS: Have the signing service return a complete CMS container, not a raw signature value. The SDK can embed the container, but validation depends on the public key type in the signing certificate. SDK validation support is limited to RSASSA-PSS public keys. With a standard RSA public key (rsaEncryption), the SDK may report integrity.failed even if it embedded the container successfully. Before integrating RSA-PSS, validate the output PDF with the certificates and signing parameters you plan to use.

If you need a certificate for testing, use generatePKCS12Cert() in Create Digital Certificates to generate an RSA-2048 test certificate. For local ECDSA signing, provide a PKCS#12 file that contains the ECDSA certificate and its matching private key.

Digest Algorithms ​

A digest is a short digital fingerprint of the data to be signed. SHA-256, SHA-384, and SHA-512 compute that fingerprint; RSA and ECDSA are used to sign. For two-phase signing, configure the SDK and your signing service to use the same digest algorithm.

Digest AlgorithmLocal Signing OutputTwo-Phase: Complete CMSTwo-Phase: Raw SignatureRFC 3161 Timestamp Request
SHA-256✅ Supported✅ Supported✅ Supported✅ Supported
SHA-384—✅ Supported✅ Supported—
SHA-512—✅ Supported✅ Supported—

A dash (—) means the algorithm is not listed as supported for that workflow. The two-phase columns apply to RSA-PKCS#1 v1.5, ECDSA P-256, and ECDSA P-384. RSA-PSS has the limitations described above. The timestamp request column shows which digest the SDK sends to the timestamp authority, not which algorithm the authority uses to sign the returned timestamp.

Certificate Formats ​

Use CaseSupported FormatWhat to Provide
Local signingPKCS#12 (.p12, .pfx)Give writeSignature() the path to the file containing the signing certificate and its private key, along with the file password.
Embed a complete CMS containerDetached CMS/PKCS#7 containerHave the signing service include the signer certificate and any required intermediate certificates. Pass the complete container to fillWithContainer().
Embed a raw signature valueDER-encoded X.509 signer certificate; DER bytes for each certificate in the chainWhen preparing the signature, pass the signer certificate to setSignerCertificateDer(). If you need to supply a chain, pass the DER bytes for each certificate to setCertificateChainDer(). Convert PEM certificates to DER first.
Validate the certificate chainTrusted root certificates in PEM formatSet the path to the trusted roots with setTrustedCertPath(). If you have a DER certificate or a .p7b container, export the required root certificate as PEM first.

Validate the signed PDF after embedding the signature. Successful embedding only confirms that the signature was written. Before delivering the PDF, validate the output to check both the integrity of the signed content and whether the signing certificate is trusted.