Skip to main content

Encryption

The encryption object adds password protection to the generated PDF and DOCX. You can set separate user and owner passwords and control what actions readers are allowed to perform.

Encrypted PDFs are not archival

PDF/A forbids encryption. An encrypted PDF is delivered without its PDF/A claim, and the render notes it. A definition that claims a PDF/A part and also sets encryption is refused: choose one. To keep a document both archival and confidential, leave the PDF unencrypted and protect it where it is stored and sent. See Conformance.

Properties​

PropertyTypeDefaultDescription
encryptionTypestring"aes256"The cipher: aes256, aes256Gcm or aes128 (see below)
userPasswordstring—The password that opens the document. Absent, it opens without one and the permissions still hold
ownerPasswordstring—The password that lifts the permissions. Absent or empty, a random one is drawn, so nobody holds it; it is never set to the user password
permissionsobject—What a reader may do without the owner password (see below)
encryptMetadatabooleantrueWhether the document's metadata is encrypted with it; false leaves it readable to a search tool
encryptEmbeddedFilesOnlybooleanfalseEncrypts only the attached files; the pages are written in clear, though a reader still asks for the user password, when one is set, as the file opens

Encryption types​

TypeNotes
aes256AES-256, the default and the recommended cipher
aes256GcmAES-256 in GCM mode, defined over PDF 2.0. It never changes the version of the file: the document states PDF 2.0 itself, by metadata.pdfVersion: "2.0" or a ua-2 or Well-Tagged PDF claim. Refused in any document that does not
aes128AES-128, deprecated by PDF 2.0. Refused in a PDF 2.0 document: beside a "2.0" pin, a ua-2 claim or a Well-Tagged PDF level

RC4 is not offered: it is broken, and PDF 2.0 deprecates it.

An encrypted PDF 2.0 file carries an integrity code

An encrypted PDF 2.0 file carries an integrity code over the whole file (ISO/TS 32004), and tells the reader it must check it, so the code cannot be stripped unnoticed. A reader that does not implement ISO/TS 32004 cannot open such a file: at least one widely used reader declines it. Where the widest reach matters more than that check, pin metadata.pdfVersion: "1.7": a 1.7 file carries no integrity code (and aes256Gcm is then written as aes256). A claim that needs PDF 2.0, such as ua-2, keeps the file at 2.0.

When its pages are encrypted, the file also declares, as a document requirement (ISO 32000-2 12.11), that a reader needs this encryption to display it, so a reader that cannot decrypt it can say why. At least one widely used reader shows a warning when it opens a file carrying a document requirement, saying the document requires features it does not support, and then opens it; it does so for requirement types it does support too. Both follow the standards, and DocPayload writes them as the standards provide (see Conformance). A file whose attachments alone are encrypted (encryptEmbeddedFilesOnly) declares no requirement, since its pages display without the password.

Permissions​

The permissions object controls what a user who opens the document with the user password is allowed to do. Absent, printing at full quality is allowed and nothing else, and the DOCX is read-only; {} grants nothing.

PropertyTypeDefaultDescription
printbooleanfalseAllow printing
printHighQualitybooleantrueAllow printing at full quality; false allows degraded printing only, so set print too
modifybooleanfalseAllow modifying document content
copybooleanfalseAllow copying text and graphics
annotatebooleanfalseAllow adding comments and filling forms
fillFormbooleanfalseAllow filling form fields
assemblebooleanfalseAllow inserting, rotating, or deleting pages

Extraction for assistive technology is always allowed, whatever copy says, so a screen reader can still read an encrypted document aloud (ISO 32000-2 Table 22, bits 5 and 10).

In a DOCX​

A DOCX is protected from the same encryption object, as far as Word's format allows:

KeyIn the DOCX
userPasswordThe file is encrypted and opens under this password, with AES-256. Without one, the DOCX is not encrypted and opens without a password
ownerPassword and permissionsBecome Word's editing restriction, locked under the owner password: read-only, comments only, or filling in forms, by the permissions granted. Allowing modify leaves editing unrestricted
encryptionTypeA DOCX is always encrypted with AES-256
permissions.print, copy, assemble, printHighQualityNo equivalent in a DOCX. A denied one is reported, and not applied
encryptMetadata, encryptEmbeddedFilesOnlyNo equivalent: the whole file is encrypted
note

Word's editing restriction keeps honest readers from editing, but the Office Open XML standard says it is not a security feature. Only userPassword makes the content unreadable without the password.

Examples​

Basic password protection​

{
"document": {
"encryption": {
"encryptionType": "aes256",
"userPassword": "viewerPass123",
"ownerPassword": "adminPass456"
},
"content": [
{ "p": "This document requires a password to open." }
]
}
}

Read-only with print allowed​

{
"document": {
"encryption": {
"encryptionType": "aes256",
"userPassword": "readonly",
"ownerPassword": "owner",
"permissions": {
"print": true,
"copy": false,
"modify": false,
"annotate": false,
"fillForm": false,
"assemble": false
}
},
"content": [
{ "p": "This document can be viewed and printed, but not edited or copied." }
]
}
}

Form-fillable only​

{
"document": {
"encryption": {
"encryptionType": "aes128",
"userPassword": "",
"ownerPassword": "formsAdmin",
"permissions": {
"print": true,
"fillForm": true,
"modify": false,
"copy": false,
"annotate": false,
"assemble": false
}
},
"content": [
{ "p": "Fill in the fields below:" }
]
}
}

An empty userPassword allows opening without a password while still enforcing permission restrictions.

Unencrypted metadata​

{
"document": {
"metadata": {
"title": "Confidential Report",
"author": "Operations Team"
},
"encryption": {
"encryptionType": "aes256",
"userPassword": "secure",
"ownerPassword": "admin",
"encryptMetadata": false
},
"content": [
{ "p": "Metadata is searchable even though the document is encrypted." }
]
}
}

This is useful when documents need to be indexed by a document management system without requiring the password.