跳到正文
DEV Community· Aqsam Husnain·· 38 分鐘前AI 評分37

ISO 32000 PDF 加密解析:/P 權限位元遮罩、AES-256 金鑰推導與無損串流解密

Inside ISO 32000 PDF Encryption: Owner Bitmasks (/P), AES-256 Key Derivation & Lossless Stream Decryption

AI 導讀

文章解析 ISO 32000-1 和 ISO 32000-2 下 PDF 加密的運作方式,聚焦 /Encrypt 字典、32 位元 /P 權限位元遮罩,以及 Owner 密碼鎖與 User 開啟密碼的差異。Owner 鎖定的檔案可透過空白 User 密碼解密;逐物件解密則可保留書籤、超連結及 AcroForm 欄位。

正文

If you have ever built a document ingestion pipeline, an automated accounting parser, or an RAG/LLM indexing service, you have inevitably encountered encrypted PDF uploads that crash your worker queue.

While scaling the document processing pipeline for the Free Online PDF Password Remover, PDF Compressor, and PDF Merger on UtilifyAI, we benchmarked how modern PDF security handlers (R=2 through R=6) operate under the ISO 32000-1 and ISO 32000-2 specifications.

Here is a technical deep dive into the /Encrypt dictionary, the 32-bit /P permissions bitmask, and why Owner locks behave completely differently from User open passwords.


1. The /Encrypt Trailer Dictionary: Why Owner Locks Don't Hide Content

When a user opens a PDF that restricts printing, text copying, or page assembly without prompting for a password, many developers assume the file is unencrypted. In reality, the file is encrypted, and its trailer points to an /Encrypt dictionary containing:

  • /Filter /Standard
  • /V (Algorithm version: 2 for RC4-128, 4 for AES-128, 5 for AES-256)
  • /R (Standard security handler revision: 3, 4, 5, or 6)
  • /O and /U (32-byte or 48-byte Owner and User validation hashes)
  • /P (A signed 32-bit integer encoding the permissions bitmask)

Why can a PDF reader render the pages immediately if the streams are encrypted? Because when only an Owner Password is set, the file is encrypted using the default empty User Password ("", padded with the standard 32-byte Adobe padding string 28 BF 4E 5E...).

Any PDF parser can authenticate against the /U entry using the empty password string, derive the master file encryption key, and decrypt every object stream in memory. Compliance with the /P bitmask is purely voluntary on the part of the client viewer.


2. Decoding the 32-Bit /P Permissions Bitmask

In the ISO 32000 specification, the /P entry in the /Encrypt dictionary is a 32-bit signed integer where specific bit positions (1-indexed) grant or deny operations when set to 1 or 0:

PDF_PERMISSION_BITS = {
    3:  "Print document (low-resolution / draft)",
    4:  "Modify contents (other than annotations/forms)",
    5:  "Copy or extract text and graphics",
    6:  "Add or modify text annotations and interactive form fields",
    9:  "Fill in existing interactive form fields (AcroForms)",
    10: "Extract text/graphics for accessibility (screen readers)",
    11: "Assemble document (insert, rotate, delete, or merge pages)",
    12: "Print document at full high-resolution vector fidelity",
}

def inspect_permissions(p_int: int) -> dict:
    return {
        desc: bool(p_int & (1 << (bit - 1)))
        for bit, desc in PDF_PERMISSION_BITS.items()
    }

When Bit 11 (Assemble document) or Bit 5 (Copy/extract) is cleared (0), downstream tools like PDF mergers or LLM text extractors fail unless the /Encrypt dictionary is cleanly stripped first.


3. Lossless Stream Decryption vs. Browser Print Spoolers

A common mistake in amateur web apps (and manual user workflows like Chrome's "Print to PDF") is routing an unlocked PDF through a virtual print spooler or Ghostscript rasterizer. Doing so flattens /Outlines (table-of-contents bookmarks), strips /Annots (hyperlinks), and destroys /AcroForm fields.

Instead, object-level decryption authenticates the file encryption key (using either the empty user string "" for Owner-locked files or the user-supplied passphrase for User-locked AES-128/AES-256 files), decrypts every indirect stream and string object in place, and writes out a clean cross-reference table (xref) without an /Encrypt trailer entry.


4. Free Zero-Login PDF & AI Document Utilities on UtilifyAI

If you need to unlock, merge, compress, or extract quizzes from PDF documents without daily task caps, watermarks, or account walls, try our live tools:

Read our full 5,300-word 2026 benchmark comparing the top 7 free PDF password removers here: How to Unlock a Password-Protected PDF Online Free (2026): Best Free PDF Password Removers Compared.

來源:DEV Community · dev.to