Public-Key Encrypted Document Reload
Documents encrypted with the public-key security handler (/Filter /Adobe.PPKLite or /Adobe.PubSec, /SubFilter adbe.pkcs7.s4/s5) now load when the caller supplies the recipient private key
Key material
Assign THotPDF.PubSecKeyMaterial (a THPDFPFXKeyMaterial from HPDFParsePFX) before calling LoadFromFile. During the bounded-range prescan the file key is recovered: every /Recipients envelope is unwrapped with the RSA-OAEP private key (seed and permissions recovered from the CMS EnvelopedData), and the file key is re-derived exactly like the writer does - SHA-256 of seed plus envelopes for AES-256, SHA-1 for the legacy key lengths
Recipient selection
PubSecRecipientQuery (a reference to function(Context: Pointer; RecipientCount: Integer): Integer) selects which envelope index the supplied key unwraps; without a callback every recipient is tried until one unwraps. PubSecRecipientQueryContext carries the caller state
Writer fixes
Round-tripping exposed three writer defects, all fixed: recipient envelopes were corrupted by a binary-through-Unicode string round-trip, the file-key digest hashed envelope bytes with a one-byte offset, and /Recipients strings were encrypted like ordinary strings (every viewer needs them plaintext); envelopes now opt out through an explicit SkipEncryption flag on the string object
Authenticated incremental updates
The modern Windows THotPDF component retains authenticated recipient keys for later form and annotation policy checks and authenticated incremental saves
Assign the decryption recipient's PubSecKeyMaterial before BeginIncrementalUpdate or ordinary loading, then use the existing form import methods and SaveIncrementalUpdateAuthenticated workflow; the recipient identity can differ from the identity that signed the document
Permitted field changes preserve the original signed byte prefix, CMS value and permanent file identifier; DocMDP and FieldMDP restrictions continue to govern which changes can be published
Distinct crypt-filter recipients
AESV2 and AESV3 filters can have independent recipient envelopes for strings, default streams and explicitly selected streams, including object-stream containers
Default StmF and StrF filters use a Recipients array whose CMS payload contains a 20-byte seed followed by four permission bytes; a filter used only by an explicit Crypt selection uses a single CMS byte string containing the 20-byte seed
The four FF bytes for unencrypted metadata belong only to the default StmF key derivation; an independent explicit filter or StrF key does not inherit that suffix
Indirect crypt-filter definitions and recipient objects retain their own object identities, and strings inside an object-stream member are recovered through the container rather than decrypted a second time
Authority and retry
Crypt-filter names compare by decoded PDF name identity in loading, retained lookup and incremental writing, following ISO 32000-2 clause 7.3.7: /StreamCF and /Stream#43F select the same filter, /Stream#2343F stays the distinct literal name Stream#43F, hexadecimal escapes decode exactly once, and identity remains case-sensitive
Equivalent spellings mix freely between CF definition keys, StmF, StrF and EFF selectors, explicit Crypt DecodeParms names and the Crypt operator itself; a literal # in a name never decodes a second time, so it cannot silently alias another filter
Retained keys are bound to the authenticated encryption dictionary, resolved filter and recipient configuration, permanent identifier and payload object number and generation
An unknown filter or an own recipient envelope that the supplied identity cannot open is rejected; it does not borrow the default document key
Cancellation or policy rejection preserves the source and the caller's graph transaction; after rollback, a permitted operation can retry on the same document
Headless and native Linux profile
The headless document accepts the same recipient identities: pass one or more PKCS#12 byte buffers and passwords to THPDFHeadlessDocument.LoadFromFile(FileName, Password, RecipientIdentities) before any other call. The file key is recovered from the CMS envelopes in-process (RSA-OAEP key transport and key-agreement identities) and re-derived exactly like the writer for the V=5 AESV3, V=4 AESV2 and V=1/V=2 RC4 generations, including crypt filters that carry their own /Recipients arrays; an own envelope the identities cannot open fails closed
Authenticated incremental publication works the same way: update fields or sign, save, and reopen the successor revision with the same identity. The published file keeps every source byte as its prefix and reuses the original recipient envelopes, so the signing identity can differ from the recipient identity
The Linux C ABI exposes the identity through hpdf_document_supply_recipient_identity(handle, pfx, pfx_length, password, password_length) before hpdf_document_load_from_io; the identity stays on the handle for every intermediate work copy, including sign and form-import operations, and can be replaced or cleared with a null pfx
Fresh headless documents encrypt to new recipients as well: call EnablePubKeyEncryption on the headless canvas with the recipient certificates and a key type (aes256, aes128 or rc4-128) before saving; the envelopes, file key and the writer-shaped /Encrypt dictionary are built in-process, with V=4/V=5 carrying the envelopes inside the crypt filter exactly like the component writer
PKCS#12 parsing is pure in-process software on every platform: PBES2 with AES-CBC, 3DES-CBC or RC2-CBC schemes and the legacy PKCS#12 PBE 3DES and RC2 profiles no longer depend on the Windows CryptoAPI provider