EncryptionUtils
Overview
EncryptionUtils is a class in Aspose.PDF FOSS for Python.
Utility class for PDF-compliant AES-CBC, RC4 encryption, and key derivation.
This class provides 15 methods for working with EncryptionUtils objects in Python programs.
Available methods include: compute_file_encryption_key, compute_hash_v5, compute_owner_key_v4, compute_user_key_v4, compute_user_owner_keys_v6, decrypt_aes_cbc, decrypt_rc4, decrypt_writer_encrypted_stream, derive_object_key, encrypt_aes_cbc, encrypt_perms_v6, encrypt_rc4, and 3 additional methods.
All public members are accessible to any Python application after installing the Aspose.PDF FOSS for Python package.
Methods
| Signature | Description |
|---|---|
encrypt_aes_cbc(key: bytes, data: bytes, iv: bytes | None) → bytes | Encrypt data using AES-CBC with PKCS7 padding. |
decrypt_aes_cbc(key: bytes, data: bytes) → bytes | Decrypt data encrypted by encrypt_aes_cbc. |
encrypt_rc4(key: bytes, data: bytes) → bytes | Encrypt data using RC4 (ARC4) algorithm. |
decrypt_rc4(key: bytes, data: bytes) → bytes | Decrypt data using RC4 (ARC4) algorithm. |
decrypt_writer_encrypted_stream(file_key: bytes, algorithm: str, obj_id: int, data: bytes) → bytes | Decrypt stream bytes produced by :meth:PdfWriterV0._encrypt_data. |
compute_owner_key_v4(owner_password: str, user_password: str, key_length: int, revision: int) → bytes | Compute Owner password value (O) per Algorithm 3.3. |
compute_file_encryption_key(password: str, o_value: bytes, p_value: int, file_id: bytes, key_length: int, revision: int, encrypt_metadata: bool) → bytes | Compute the file encryption key per Algorithm 3.2. |
compute_user_key_v4(password: str, o_value: bytes, p_value: int, file_id: bytes, key_length: int, revision: int, encrypt_metadata: bool) → tuple[bytes, bytes] | Compute User password value (U) and encryption key per Algorithm 3.4/3.5. |
verify_password_v4(password: str, u_value: bytes, o_value: bytes, p_value: int, file_id: bytes, key_length: int, revision: int, encrypt_metadata: bool) → bytes | None | Verify password and return encryption key if valid. |
compute_hash_v5(password: bytes, salt: bytes, user_key: bytes) → bytes | Compute hash for V5/R6 per Algorithm 2.B (ISO 32000-2). |
compute_user_owner_keys_v6(user_password: str, owner_password: str, file_key: bytes | None) → tuple[bytes, bytes, bytes, bytes] | Compute U, O, UE, OE values for AES-256 (R6) per ISO 32000-2. |
verify_password_v6(password: str, u_value: bytes, o_value: bytes, ue_value: bytes, oe_value: bytes) → bytes | None | Verify user or owner password for PDF V5 revision 5/6; return file key or None. |
encrypt_perms_v6(file_key: bytes, p_value: int, encrypt_metadata: bool) → bytes | Encrypt permissions and metadata flag for R6. |
derive_object_key(file_key: bytes, obj_num: int, gen_num: int, use_aes: bool) → bytes | Derive object-specific key per Algorithm 3.1. |
generate_file_id() → bytes | Generate a random 16-byte file ID for new documents. |