Class PdfEncryptor


  • public final class PdfEncryptor
    extends java.lang.Object
    Encrypts an in-memory COSDocument for output, using the PDF Standard security handler -- the write-side counterpart of StandardSecurityHandler (a reader, which deliberately doesn't expose a forward/encrypting direction). Lives in this package to reuse the package-private RC4/AES/LegacyKeyDerivation/ AES256KeyDerivation primitives, the same way the test suite's EncryptedPdfSampleBuilder does -- this class generalizes that same math to walk an arbitrary already-built document's whole object graph instead of a fixed tiny fixture.

    Call this on a fully-built, still-plaintext COSDocument (e.g. a com.pd4ml.pdf.merge merge target) after all content is in place but before handing it to a writer -- every string and stream reachable from the document's indirect objects is encrypted in place, and a fresh /Encrypt dictionary plus /ID are registered on the document.