Skip to Content
NexPDF

Digital signatures

Sign PDFs with PAdES on iOS and Android using a PKCS#12 file or an external key, add long-term validation, and verify signatures with NexPDF for React Native.

English

License module

Signing, LTV and verification (with or without your own roots) need the signatures module (Business tier and above).

Every signing call resolves to the complete signed file as base64. Keep those bytes as they are: saving the document object again afterwards breaks the signature.

Sign with a PKCS#12 file

sign(p12Base64, password, options) signs with a .p12 or .pfx identity:

const doc = await NexPdf.open(contractBase64);
const signed = await doc.sign(p12Base64, 'p12-password', {
  reason: 'Approved',
  location: 'Lisbon',
  tsa_url: 'http://timestamp.example.com',   // optional: PAdES B-T
  ltv: true,                                  // optional: PAdES B-LT
  appearance: { page: 0, rect: [360, 60, 560, 120], text: 'Signed by Ana Silva' },
});

Options: name, reason, location, contact, field (an existing signature field), tsa_url, ltv, level (B-B, B-T, B-LT or B-LTA, see Long-term signatures), timestamp (the B-LTA document timestamp's hash, field and reserved) and appearance (page, rect, ink strokes, text). A wrong password rejects with NexPdfError('incorrect password'). NexPdf.api.pkcs12InfoJson(p12Base64, password) shows the certificate.

For tests, doc.signPades(signer, reason, location) signs with a new self-signed certificate.

Sign with a secure enclave, smart card or cloud key

External signing works in three calls with no state kept between them:

// The signer certificate file (PEM: the certificate, then its chain) as base64.
const certBase64 = signerCertBase64;

const prepared = await doc.prepareExternalSignature(certBase64, JSON.stringify({ reason: 'Approved' }));
const toSign = await NexPdf.api.externalSignatureData(prepared, certBase64);

const signature = await myKeyStore.signSha256Rsa(toSign);   // your device key or KMS, base64

const signed = await NexPdf.api.completeExternalSignature(prepared, certBase64, signature, 0, null);

algorithm is 0 for RSA PKCS#1 v1.5 with SHA-256 or 1 for ECDSA with SHA-256 (DER or raw r||s). Devices that take a digest sign the SHA-256 of toSign. The last argument takes {"tsa_url": "...", "ltv": true} and also "level", so an external signature can be B-LTA too.

Long-term validation

NexPdf.api.addLtv(signedBase64) adds the OCSP responses and CRLs (a DSS) to a signed file so the signature can be validated after the certificates expire:

const withLtv = await NexPdf.api.addLtv(signed);

Verify signatures

for (const s of await NexPdf.verifySignatures(signed)) {
  console.log(s.signer, s.level, s.digest_ok && s.signature_ok ? 'valid' : 'INVALID');
}

const report = JSON.parse(await NexPdf.api.verifySignaturesWithRootsJson(signed, companyRootsPem));

Each entry includes field, signer, subject, digest_ok, signature_ok, covers_whole_document, reason, signing_time, timestamp_ok, chain_ok, trusted, revocation, ltv, level, pades_level (B-B, B-T, B-LT or B-LTA) and document_timestamp (true for a document timestamp, whose signer is the timestamp authority).

Long-term archival

For PAdES B-LTA, document timestamps and archive timestamp renewal, see Long-term signatures.

Handwritten signatures

A drawn signature without cryptography is an ink annotation: addInkSignature(page, color, width, strokes). See Annotations. The reader offers both in its signatures mode.

On this page