tecnickcom/tc-lib-pdf-encrypt
PHP library to handle PDF encryption for TCPDF/TC-Lib-PDF: generate and apply user/owner passwords, set permissions (print/copy/modify), and manage standard PDF security settings for producing protected PDF documents.
PDF encryption primitives for password protection and permission control.
๐ Part of the tc-lib-pdf / TCPDF ecosystem (100M+ installs). Sponsor its maintenance โ
tc-lib-pdf-encrypt implements core encryption routines used by PDF generation and processing stacks, including password handling and permission flags.
The package encapsulates PDF security mechanics behind a focused API so consuming libraries can apply encryption policies without reimplementing cryptographic details. It is built for interoperability with standard PDF readers and for clear separation between document logic and security concerns.
| Namespace | \Com\Tecnick\Pdf\Encrypt |
| Author | Nicola Asuni info@tecnick.com |
| License | GNU LGPL v3 - see LICENSE |
| API docs | https://tcpdf.org/docs/srcdoc/tc-lib-pdf-encrypt |
| Packagist | https://packagist.org/packages/tecnickcom/tc-lib-pdf-encrypt |
RC4 modes (0 and 1) are cryptographically broken and deprecated. RC4-40 (mode 0) and RC4-128 (mode 1) are no longer considered secure. Both modes emit an
E_USER_DEPRECATEDnotice at runtime. Use AES-128 (mode 2), AES-256 R5 (mode 3), or AES-256 R6 / PDF 2.0 (mode 4) for all new documents.
| Mode | Algorithm | Security |
|---|---|---|
| 0 | RC4-40 | Broken: do not use |
| 1 | RC4-128 | Broken: do not use |
| 2 | AES-128 | Acceptable for legacy compatibility |
| 3 | AES-256 R5 (PDF 1.7 ext.) | Recommended |
| 4 | AES-256 R6 (PDF 2.0 / ISO 32000-2) | Recommended (most current) |
$encryptMetadata)$encryptEmbeddedFiles, /EFF dictionary entry)decryptString() companion to encryptString()hash, opensslcomposer require tecnickcom/tc-lib-pdf-encrypt
<?php
require_once __DIR__ . '/vendor/autoload.php';
// AES-256 R6 (mode 4, recommended)
$encrypt = new \Com\Tecnick\Pdf\Encrypt\Encrypt(
enabled: true,
file_id: md5('unique-file-id'),
mode: 4,
permissions: ['print', 'copy'],
user_pass: 'userpassword',
owner_pass: 'ownerpassword',
);
$cipher = $encrypt->encryptString('secret payload', $objectNumber = 1);
echo bin2hex($cipher);
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Pass the encryption dictionary produced by the Encrypt instance.
$decrypt = new \Com\Tecnick\Pdf\Encrypt\Decrypt($encrypt->getEncryptionData());
if ($decrypt->authenticate('userpassword')) {
// For AES modes the PKCS#7 padding is stripped automatically, so the
// exact original plaintext is returned. RC4 modes are symmetric.
$plain = $decrypt->decryptString($cipher, $objectNumber = 1);
echo $plain;
}
On OpenSSL 3 systems, legacy providers may be disabled by default. Enable legacy support when required by your runtime policy.
make deps
make help
make qa
make rpm
make deb
For system packages, bootstrap with:
require_once '/usr/share/php/Com/Tecnick/Pdf/Encrypt/autoload.php';
Contributions are welcome. Please review CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.
How can I help you explore Laravel packages today?