Digital signatures
Sign PDFs with your certificate, a self-signed one or a key you hold (ICP-Brasil included), and verify the signatures in a PDF.
The sign action signs the PDF in a build. Signatures are PAdES baseline (CMS with SHA-256), at
the level you choose: B-B by default, or B-T, B-LT and B-LTA with a trusted timestamp and the data
to validate the signature for years (see Timestamps and long-term validation).
| Field | Meaning |
|---|---|
certificate | The field of an uploaded PKCS#12 file (.p12 or .pfx) with your certificate and private key. Left out, the server makes a self-signed certificate for this one signature. |
password | The PKCS#12 file's password. Only with certificate. |
name, reason, location, contact | Shown in the signature panel of PDF readers (optional, up to 200 characters each). |
field | The signature field's name (optional; Signature1 by default). |
appearance | Makes the signature visible: page (from 0), rect ([left, bottom, right, top] in PDF points, 72 per inch, from the bottom left corner) and text (optional). Left out, the signature is invisible. |
level | The PAdES level: B-B (default), B-T, B-LT or B-LTA. |
policy | A signature policy: icp-brasil for ICP-Brasil signatures (optional). |
timestamp_authority | Your own time-stamp authority for B-T and above: url, and username and password (HTTP Basic) or token (bearer) when it asks for them (optional; see Your own time-stamp authority). |
sign must be the last action, and the output a PDF that is not linearised: any change after
signing would break the signature. Fill, flatten, redact or convert to PDF/A first, in the same
build.
Cost: 1 unit per signature, plus 1 per level above B-B (see below).
Sign with a self-signed certificate
Good for proving a file has not changed since your system produced it. Readers show the signature as valid but the signer as unknown, since no authority vouches for the certificate.
curl https://api.nexpdf.dev/v1/build \
-H "Authorization: Bearer $NEXPDF_API_KEY" \
-F doc=@contract.pdf \
-F 'instructions={
"parts": [
{
"file": "doc"
}
],
"actions": [
{
"type": "sign",
"reason": "Approved",
"location": "Lisbon"
}
]
}' \
-o contract-signed.pdfSign with your certificate, visibly
Send the PKCS#12 file as one more field and name that field in certificate. The file and its
password are used for this request only and are never stored. Keep the password in a secret
store, not in your code.
curl https://api.nexpdf.dev/v1/build \
-H "Authorization: Bearer $NEXPDF_API_KEY" \
-F doc=@contract.pdf \
-F cert=@company.p12 \
-F 'instructions={
"parts": [
{
"file": "doc"
}
],
"actions": [
{
"type": "sign",
"certificate": "cert",
"password": "p12-password",
"reason": "Approved for payment",
"appearance": {
"page": 0,
"rect": [
360,
48,
560,
108
],
"text": "Signed by Jane Doe"
}
}
]
}' \
-o contract-signed.pdfFill, close and sign a form
Actions run in order, so a submitted form can be filled, flattened and signed in one request.
curl https://api.nexpdf.dev/v1/build \
-H "Authorization: Bearer $NEXPDF_API_KEY" \
-F doc=@application.pdf \
-F 'instructions={
"parts": [
{
"file": "doc"
}
],
"actions": [
{
"type": "fill_form",
"values": {
"full_name": "Jane Doe",
"accept_terms": true
}
},
{
"type": "flatten_forms"
},
{
"type": "sign",
"reason": "Submitted by the applicant"
}
]
}' \
-o application-signed.pdfTimestamps and long-term validation
A B-B signature records the signing time from the server's clock. The higher levels add proof that holds up later, when the certificate has expired or been revoked:
| Level | Adds | Cost |
|---|---|---|
B-T | A timestamp from a trusted timestamp authority (RFC 3161) over the signature: proof of when it was signed. | +1 unit |
B-LT | Also the certificate chain and its revocation status (OCSP answers and CRLs) at signing time, stored in the PDF, so it can be validated without asking anyone later. | +2 units |
B-LTA | Also a document timestamp over all of it, so the whole file can be re-timestamped before its algorithms age. The level for archives. | +3 units |
curl https://api.nexpdf.dev/v1/build \
-H "Authorization: Bearer $NEXPDF_API_KEY" \
-F doc=@contract.pdf \
-F 'instructions={
"parts": [
{
"file": "doc"
}
],
"actions": [
{
"type": "sign",
"reason": "Approved",
"level": "B-LTA"
}
]
}' \
-o contract-signed.pdfB-LT and B-LTA fetch revocation data from the addresses in your certificate. With a self-signed
certificate there is nothing to fetch, so the signature is still timestamped but its signer is
still unknown to readers: use your own certificate for signatures others must trust. If the
timestamp authority does not answer, the request fails with 503 unavailable and is retried by the
client libraries; nothing is charged.
Your own time-stamp authority
By default the time-stamps come from the service's authority. To use one you have a contract with
(for ICP-Brasil, your ACT), give it in timestamp_authority:
| Field | Meaning |
|---|---|
url | The authority's RFC 3161 address, http or https, on port 80 or 443 and a public address. |
username, password | HTTP Basic credentials, when the authority asks for them. |
token | A bearer token, instead of username and password. |
Credentials are sent only over https, only to that address (never to a redirect), with each
time-stamp request of this signature, and are not stored: they live as long as the request, or as
the prepared signature in two steps. They are never written to logs.
timestamp_authority needs level B-T or above. When your authority refuses or does not answer,
the request fails with 422 fetch_failed, naming its host and HTTP status (a 401 means the
credentials), and nothing is charged.
ICP-Brasil signatures
In Brazil, a signature with an ICP-Brasil certificate has the legal value of a handwritten one
(MP 2.200-2/2001), as long as it follows the signature policies of DOC-ICP-15.03. Add
"policy": "icp-brasil" to sign and the signature follows them:
level | Policy | What it is |
|---|---|---|
B-B | AD-RB v1.3 (basic reference) | The signature, with the policy identifier. |
B-T and above | AD-RT v1.3 (time reference) | Also a time-stamp from a time-stamp authority accredited in ICP-Brasil (an ACT). |
What changes in the file: the signed attribute naming the policy (its OID, the hash of the policy
and its address at politicas.icpbrasil.gov.br), the signature dictionary's
/Filter /PBAD_PAdES and /SubFilter /PBAD.PAdES that the policy requires, and RSA named as
sha256WithRSAEncryption. Nothing the policies forbid is added (no signing time attribute, no
Adobe revocation attribute).
The signature is valid in Brazil only when the certificate is an ICP-Brasil one (an A1 file from a certification authority, or an A3 token or card through two steps). The policies accept RSA keys of 2048 bits or more, ECDSA and EdDSA, with SHA-256 or SHA-512.
curl https://api.nexpdf.dev/v1/build \
-H "Authorization: Bearer $NEXPDF_API_KEY" \
-F doc=@contrato.pdf \
-F cert=@certificado-a1.pfx \
-F 'instructions={
"parts": [
{
"file": "doc"
}
],
"actions": [
{
"type": "sign",
"certificate": "cert",
"password": "senha-do-certificado",
"reason": "Aceite do contrato",
"level": "B-B",
"policy": "icp-brasil"
}
]
}' \
-o contrato-assinado.pdfTo check the result, /v1/verify reports the policy (below), and the government's validator at
validar.iti.gov.br checks it against the ICP-Brasil rules. Adobe
Acrobat shows these signatures as valid only with the ITI's PBAD plug-in, because of their
/Filter.
AD-RT needs a time-stamp from an ACT. Use your own, with the credentials your contract gives you,
in timestamp_authority:
curl https://api.nexpdf.dev/v1/build \
-H "Authorization: Bearer $NEXPDF_API_KEY" \
-F doc=@contrato.pdf \
-F cert=@certificado-a1.pfx \
-F 'instructions={
"parts": [
{
"file": "doc"
}
],
"actions": [
{
"type": "sign",
"certificate": "cert",
"password": "senha-do-certificado",
"reason": "Aceite do contrato",
"level": "B-T",
"policy": "icp-brasil",
"timestamp_authority": {
"url": "https://act.example.com.br/tsp",
"username": "minha-empresa",
"password": "senha-da-act"
}
}
]
}' \
-o contrato-assinado.pdfWithout timestamp_authority, AD-RT uses the service's ACT where it has one; where it has none, the
answer is 422 not_available for B-T and above with icp-brasil, before any work and at no
cost. AD-RB needs nothing else.
Sign with a key you hold
When the private key cannot leave its device (an ICP-Brasil A3 token or smart card, an HSM, a cloud KMS, a remote signing service), sign in two steps. Only the certificate is sent; the key never reaches the API.
POST /v1/sign/preparewithdocument,certificate(the signer certificate, PEM or DER; a PEM may carry its chain after it) andoptions, a JSON object with thesignaction's fields butcertificateandpassword(name,reason,location,contact,field,appearance,level,policy,timestamp_authority). The answer is201withid,to_be_signed(base64),to_be_signed_sha256(hex, for devices that sign a digest),expires_at(an hour by default;expires_insets 60 to 86400 seconds),levelandpolicy.- Sign the bytes of
to_be_signedwith the key: RSA PKCS#1 v1.5 or ECDSA, both with SHA-256. POST /v1/sign/completewithidandsignature(base64). The answer is the signed PDF, with the time-stamp and validation data its level asks for.
curl https://api.nexpdf.dev/v1/sign/prepare \
-H "Authorization: Bearer $NEXPDF_API_KEY" \
-F document=@contrato.pdf -F certificate=@certificado.pem \
-F 'options={"reason":"Aceite","level":"B-T","policy":"icp-brasil"}'
# {"id":"sig_…","to_be_signed":"MYIB…","to_be_signed_sha256":"9f2c…","expires_at":…,"level":"B-T","policy":"icp-brasil-ad-rt"}
curl https://api.nexpdf.dev/v1/sign/complete \
-H "Authorization: Bearer $NEXPDF_API_KEY" \
-F id=sig_… -F signature="$(base64 < assinatura.bin)" -o contrato-assinado.pdfThe client libraries do the same with prepareSignature and completeSignature
(prepare_signature and complete_signature in Python and Ruby; the exact name in each language
is in its README), and deleteSignature drops a prepared signature before it expires.
A signature that does not match the certificate and the bytes to sign is refused with 422, and
the prepared document is kept, so the call can be repeated. Once a signature is accepted, the
prepared document is deleted from the server. Preparing is free (a file that has to be converted
to PDF costs the conversion); completing costs what a sign action costs.
Verify signatures
POST /v1/verify reads every signature in a PDF and checks it. It answers with JSON, one object
per signature; an unsigned PDF gives [].
| Key | Meaning |
|---|---|
field | The signature field's name. |
signer | The common name of the signing certificate. |
digest_ok | The signed bytes have not changed since signing. |
signature_ok | The signature matches the certificate's key. |
covers_whole_document | Nothing was added after this signature. false means a later revision exists: another signature, or an edit. |
self_signed | The certificate signed itself, so no authority vouches for the signer. |
reason, location | As the signer gave them. |
sub_filter | The signature's format: ETSI.CAdES.detached (PAdES), PBAD.PAdES (ICP-Brasil), … |
policy | null, or the policy the signature names: oid, name (such as ICP-Brasil AD-RB v1.3), hash_ok, icp_brasil and problems. |
For ICP-Brasil signatures, policy.icp_brasil is true only when every requirement checked
holds: the policy is current and its hash matches, the signature dictionary and the signed
attributes are those the policy asks for, the algorithm and key size are allowed, AD-RT has a valid
time-stamp, and the certificate chains to an AC Raiz of ICP-Brasil (v5, v10, v11 or v12, built
into the service). Otherwise problems says what fails, in plain words.
Verification checks the signature itself, not whether you trust the certificate: check signer
and, for your own certificates, that self_signed is false.
Cost: 1 unit per file.
curl https://api.nexpdf.dev/v1/verify \
-H "Authorization: Bearer $NEXPDF_API_KEY" \
-F document=@contract-signed.pdf