Troubleshooting: encryption and permission flags
Scope and boundary
Section titled “Scope and boundary”Use these entries to troubleshoot decryption failures the engine raises through
NextPDF\Exception\EncryptionException and
NextPDF\Security\Exception\DecryptionFailedException, and to understand the
boundary of Portable Document Format (PDF) permission flags.
Start with the boundary because it prevents the most common misconception: PDF permission flags in the encryption dictionary record the author’s intent. They are not an access-control mechanism enforced by this library. A reader that ignores the flags can still print, copy, or modify the content. Treat the flags as a request to a cooperating reader, not as enforcement.
Entry: encryption operation fails
Section titled “Entry: encryption operation fails”- Symptom.
EncryptionExceptionwith a message of the formEncryption operation "<op>" failed using algorithm "<algorithm>". - Likely cause. The cipher operation could not run, typically because the OpenSSL extension is missing or misconfigured, the key material is invalid, or the initialization vector (IV) size is invalid at the cipher boundary.
- Evidence / diagnosis.
getContext()returnsalgorithmandoperation. Theoperationvalue is one ofencrypt,decrypt, orkey_derivation, so you can identify which stage failed. - Resolution.
- Confirm that the OpenSSL PHP extension is installed and loaded.
- Use the
operationfield to find the failing stage. - For
key_derivation, verify the password or key inputs. - Re-run the call.
- Related. Exception reference.
Entry: decryption fails for a structural reason
Section titled “Entry: decryption fails for a structural reason”- Symptom.
DecryptionFailedExceptionwith a message of the formDecryption failed for "<algorithm>": <reason>. - Likely cause. The ciphertext could not be processed for a non-tampering reason, such as truncated ciphertext, a missing IV, or the wrong key supplied at the application programming interface (API) boundary. The integrity check did not run because there was not enough material to evaluate.
- Evidence / diagnosis.
getContext()returnsalgorithmandreason. Source documentation distinguishesDecryptionFailedExceptionfromTamperedDataException: this exception means a configuration or transport error, not tampering. Do not treat it as a security incident on its own. - Resolution.
- Read
reasonto identify the structural defect, for exampleciphertext shorter than IV+tag. - Verify that the ciphertext was transported without truncation.
- Confirm that the key supplied at the boundary is the key used to encrypt the document.
- Re-run the call.
- Read
- Related. Signature and timestamp failures.
Entry: a “tampered data” exception is raised
Section titled “Entry: a “tampered data” exception is raised”- Symptom. You receive
NextPDF\Security\Exception\TamperedDataExceptionrather thanDecryptionFailedException. - Likely cause. The integrity check ran and failed. This differs from a structural decryption failure: enough material was present to evaluate integrity, and integrity did not hold.
- Evidence / diagnosis. The source distinguishes the two classes:
DecryptionFailedExceptionis structural and not a security incident;TamperedDataExceptionindicates that the authenticated content did not verify. - Resolution.
- Treat the input as untrusted; do not consume the decrypted content.
- Re-fetch the document from a trusted source.
- If the failure persists with a known-good source, capture
getContext()for an incident report.
- Related. Signature and timestamp failures.
Entry: permission flags are not stopping a downstream action
Section titled “Entry: permission flags are not stopping a downstream action”- Symptom. A document was produced with permission flags set — for example, copy or print disallowed — but a reader still copies or prints the content.
- Likely cause. This is the expected boundary, not a defect. The permission integer passed to the core encryption dictionary builder is not applied as enforcement by this library. The flags are advisory metadata; a reader that does not honor them is not blocked by NextPDF.
- Evidence / diagnosis.
src/Security/Encryption/EncryptionDictionaryBuilder.phpdeclaresbuildDict(int $permissions, string $fileId), and documents the parameter asignored; retained for forward compatibility. The method beginsunset($permissions, $fileId). The permission flags surfaced bysrc/Inspect/PdfPermissions.phpare read-only inspection fields, not an enforcement layer. - Resolution.
- Do not rely on permission flags to stop printing, copying, or modification. They cannot be enforced by a producer library.
- Where you must restrict access, control distribution of the file itself, or apply an access-control system outside the PDF.
- Use
PdfPermissionsonly to report the flags an existing document declares, not to assert that those actions are prevented.
- Related. Signature and timestamp failures.
Entry: encryption is refused under PDF/A
Section titled “Entry: encryption is refused under PDF/A”- Symptom.
NextPDF\Security\Exception\IncompatiblePdfAModeExceptionwhen a build enables PDF/A and requests encryption. - Likely cause. The PDF/A profile forbids the
Encryptkey in the trailer. The engine refuses the combination in either call order. - Evidence / diagnosis. See the
PDF/A and PDF/UA entry for the
cited clause,
getContext()fields, and failure-path test. - Resolution.
- Decide whether the document needs archival conformance or encryption.
- Remove the call for the property you do not need.
- Re-run the pipeline.
- Related. PDF/A and PDF/UA validation.
Edge cases & gotchas
Section titled “Edge cases & gotchas”DecryptionFailedExceptionandTamperedDataExceptionmean different things: structural failure versus failed integrity. Branch on the class, not on the message.- The core encryption dictionary builder ignores the permission integer; any build that depends on permission enforcement from the core package is built on a misconception.
PdfPermissionsis populated only for encrypted documents at full inspection depth and reflects the declared flags. A populated field does not mean the action is prevented.
See also
Section titled “See also”- Exception reference
- Signature and timestamp failures
- PDF/A and PDF/UA validation
- Knowledge base index
Glossary: permission flags · authenticated decryption