Skip to content

Reader A3: encryption (decrypt side) #97

Closed

Description

@Tim81

Part of the general PDF reader epic.

Decrypt strings/streams on read for the Standard security handler — mirror of StandardSecurityHandler (AES-256 V5/R6; add RC4 / AES-128 V2/V4). Enables reading (and adding LTV to) encrypted signed PDFs.

The v1.6 MVP throws "unsupported yet" on /Encrypt.

Activity

  1. added this to the milestone on Jun 16, 2026
  2. added
    type/feature
    type/security
    needs-design
    area/reader
    on Jun 16, 2026
  3. modified the milestones: , v2.1 — PDF reader (structural) on Jun 16, 2026
  4. Tim81 commented on Aug 18, 2026

    @Tim81
    OwnerAuthor

    Blocked on #121 — a dependency the issue text does not state.

    Per-object key derivation for security handler revisions R2–R4 is
    MD5(fileKey ‖ objNum[0..3] ‖ gen[0..2] [‖ "sAlT" for AESV2]) — it consumes the generation number.
    The reader drops generations today (PdfIndirectReference has no Generation; the xref is keyed on
    object number alone), so V1/V2/V4 decryption cannot be implemented correctly until #121 lands. Sequence
    #121 first.

    Two further notes for whoever picks this up:

    • Reader: hybrid /XRefStm trailer is discarded, hiding /Encrypt #183 should land first too. An /Encrypt reachable only through a hybrid /XRefStm dictionary is
      currently invisible to the reader, which would become a silent decryption failure rather than a clean error.
    • /Crypt is not in the filter dispatch table. Filters.cs:109 throws
      Unknown PDF filter: /{name} for anything unmatched, so a /Crypt entry (ISO 32000-2 §7.4.10, normally
      /Name /Identity) surfaces as a generic InvalidDataException rather than being handled.

    Two primitives have to be hand-written; both have published specs with known-answer vectors, so neither
    needs any reference implementation:

    • RC4 — the BCL has none (its symmetric-cipher support covers AES, 3DES, DES, RC2 only).
      draft-kaukonen-cipher-arcfour-03
      gives the full KSA + PRGA and three test vectors.
    • MD5 — MD5.HashData is unsupported on Browser WASM (all BCL hash classes defer to OS libraries), which
      also puts Windows FIPS-policy behaviour outside our control. RFC 1321
      gives the algorithm and seven test vectors. A managed implementation sidesteps both problems and is
      permanently immune to CA5351 should AnalysisMode ever be raised.

    Hash2B (StandardSecurityHandler.cs:128-172) and the AES helpers (:204-240) are reusable as-is for the
    R6 path, and Kernel already grants InternalsVisibleTo("VellumPdf.Reader")
    (src/VellumPdf.Kernel/AssemblyInfo.cs:7), so a new internal decryptor in Kernel needs no config change.

  5. 1 remaining item

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/readerneeds-designtype/featuretype/security

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions