Expand description
PDF encryption support.
This module implements PDF encryption/decryption according to the PDF specification (ISO 32000-1:2008, Section 7.6). It supports:
- RC4 encryption (40-bit and 128-bit) for PDF 1.4-1.5
- AES encryption (128-bit and 256-bit) for PDF 1.6+
- Standard Security Handler (password validation, permissions)
§Encryption Algorithms
§RC4 (PDF 1.4-1.5)
- RC4-40: 40-bit key length (weak, legacy)
- RC4-128: 128-bit key length
§AES (PDF 1.6+)
- AES-128: 128-bit key length with CBC mode
- AES-256: 256-bit key length with CBC mode (PDF 2.0)
§Security Considerations
- RC4-40 is cryptographically weak and should only be used for legacy documents
- Password validation uses constant-time comparison to prevent timing attacks
- Key derivation follows PDF specification algorithms (using MD5 or SHA-256)
§References
- PDF Spec Section 7.6: Encryption
- PDF Spec Section 7.6.3: Standard Security Handler
- PDF Spec Section 7.6.5: Algorithm 2 (Key Derivation)
Re-exports§
pub use permissions::PdfPermissions;
Modules§
- permissions
- PDF §7.6.3.2
/Ppermission flag set.
Structs§
- Cert
Encrypt Dict - Certificate encryption dictionary.
- Certificate
Encryption - Certificate-based encryption builder and handler.
- Certificate
Encryption Handler - Handler for certificate-encrypted PDFs.
- Encrypt
Dict - PDF encryption dictionary (/Encrypt entry in trailer).
- Encrypt
Dict Builder - Builder for creating encryption dictionaries.
- Encryption
Handler - Main encryption handler for PDF documents.
- Encryption
Write Handler - Handler for encrypting PDF objects during write operations.
- Permissions
- PDF encryption permissions (P field).
- Recipient
Info - Recipient information for certificate encryption.
- Recipient
Permissions - Permissions for certificate-encrypted documents.
Enums§
- Algorithm
- Encryption algorithm used in the PDF.
- Cert
SubFilter - Sub-filter types for certificate encryption.
- KeyTransport
Algorithm - Key transport algorithm for encrypting the file key.
Functions§
- compute_
encryption_ key - Compute the encryption key from a password (Algorithm 2).
- compute_
owner_ password_ hash - Compute the owner password hash (Algorithm 3 for R<=4, Algorithm 8 for R>=5).
- compute_
user_ password_ hash - Compute the user password hash for the encryption dictionary (Algorithm 4/5/8).
- generate_
file_ id - Generate a unique file ID for the PDF.