tecnickcom/tc-lib-pdf-encrypt
Composer 安装命令:
composer require tecnickcom/tc-lib-pdf-encrypt
包简介
PHP library to encrypt data for PDF
README 文档
README
PDF encryption primitives for password protection and permission control.
💖 Part of the tc-lib-pdf / TCPDF ecosystem (100M+ installs). Sponsor its maintenance →
Overview
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 |
Security Notice
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) |
Features
Encryption
- RC4 and AES variants for PDF object/string encryption (modes 0–4; see Security Notice above)
- AES-256 R6 (PDF 2.0 / ISO 32000-2, mode 4) support with Algorithm 2.B (ISO 32000-2 §7.6.4.3.4) key derivation
- User and owner password workflows
- Permission flag handling for document operations
- Optional metadata encryption control (
$encryptMetadata) - Optional embedded-file stream encryption (
$encryptEmbeddedFiles,/EFFdictionary entry) - Public-key (certificate) encryption for multiple recipients
Decryption
- Password authentication for all encryption modes (RC4-40, RC4-128, AES-128, AES-256 R5/R6)
- Public-key (PKCS#7 / S/MIME) decryption for recipient private keys
- Per-object key derivation for AES-128 streams
- Round-trip
decryptString()companion toencryptString()
Integration
- Designed for direct use by PDF writer and reader components
- Helpers for PDF date formatting and hex/string transforms
- Exception-driven error handling
Requirements
- PHP 8.2 or later
- Extensions:
hash,openssl - Composer
Installation
composer require tecnickcom/tc-lib-pdf-encrypt
Quick Start
Encrypting a string
<?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);
Decrypting a string
<?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; }
OpenSSL 3 Note
On OpenSSL 3 systems, legacy providers may be disabled by default. Enable legacy support when required by your runtime policy.
Development
make deps
make help
make qa
Packaging
make rpm make deb
For system packages, bootstrap with:
require_once '/usr/share/php/Com/Tecnick/Pdf/Encrypt/autoload.php';
Contributing
Contributions are welcome. Please review CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md.
tecnickcom/tc-lib-pdf-encrypt 适用场景与选型建议
tecnickcom/tc-lib-pdf-encrypt 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 944.07k 次下载、GitHub Stars 达 11, 最近一次更新时间为 2015 年 11 月 26 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「pdf」 「encryption」 「aes」 「encrypt」 「rc4」 「tc-lib-pdf-encrypt」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 tecnickcom/tc-lib-pdf-encrypt 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 tecnickcom/tc-lib-pdf-encrypt 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 tecnickcom/tc-lib-pdf-encrypt 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A simple PHP class to encrypt a string and decrypt an encrypted string
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Encryption with AES-256 and HMAC-SHA256
AES cipher - FIPS 192 compliant
Allows installation of Laravel where the PHP Mcrypt extension is not available. Provides encryption using OpenSSL, or by disabling encryption entierly.
Encrypting fields in doctrine entities wit AES
统计信息
- 总下载量: 944.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 11
- 点击次数: 24
- 依赖项目数: 6
- 推荐数: 1
其他信息
- 授权协议: LGPL-3.0-or-later
- 更新时间: 2015-11-26