PHPackages                             tecnickcom/tc-lib-pdf-encrypt - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PDF &amp; Document Generation](/categories/documents)
4. /
5. tecnickcom/tc-lib-pdf-encrypt

ActiveLibrary[PDF &amp; Document Generation](/categories/documents)

tecnickcom/tc-lib-pdf-encrypt
=============================

PHP library to encrypt data for PDF

2.8.1(1w ago)11912.3k↓20.7%66LGPL-3.0-or-laterPHPPHP &gt;=8.2CI passing

Since May 6Pushed 1w ago2 watchersCompare

[ Source](https://github.com/tecnickcom/tc-lib-pdf-encrypt)[ Packagist](https://packagist.org/packages/tecnickcom/tc-lib-pdf-encrypt)[ Docs](https://tcpdf.org)[ GitHub Sponsors](https://github.com/sponsors/tecnickcom)[ RSS](/packages/tecnickcom-tc-lib-pdf-encrypt/feed)WikiDiscussions main Synced 3d ago

READMEChangelogDependencies (10)Versions (114)Used By (6)

tc-lib-pdf-encrypt
==================

[](#tc-lib-pdf-encrypt)

> PDF encryption primitives for password protection and permission control.

[![Latest Stable Version](https://camo.githubusercontent.com/1259e6e87a313025fc003b213d26fb3894e67c5a2bfe6286a5dab14fbec410bb/68747470733a2f2f706f7365722e707567782e6f72672f7465636e69636b636f6d2f74632d6c69622d7064662d656e63727970742f76657273696f6e)](https://packagist.org/packages/tecnickcom/tc-lib-pdf-encrypt)[![Build](https://github.com/tecnickcom/tc-lib-pdf-encrypt/actions/workflows/check.yml/badge.svg)](https://github.com/tecnickcom/tc-lib-pdf-encrypt/actions/workflows/check.yml)[![Coverage](https://camo.githubusercontent.com/9c559d688f54b836459d116529e7e437ab3a0aca99dbb1bf3caec763c3f70091/68747470733a2f2f636f6465636f762e696f2f67682f7465636e69636b636f6d2f74632d6c69622d7064662d656e63727970742f67726170682f62616467652e7376673f746f6b656e3d5076314d4e4833583376)](https://codecov.io/gh/tecnickcom/tc-lib-pdf-encrypt)[![License](https://camo.githubusercontent.com/fe8131c3faf79fe3922b1f3f4122d77e390d5a8e235c7be1f703f90a41e97089/68747470733a2f2f706f7365722e707567782e6f72672f7465636e69636b636f6d2f74632d6c69622d7064662d656e63727970742f6c6963656e7365)](https://packagist.org/packages/tecnickcom/tc-lib-pdf-encrypt)[![Downloads](https://camo.githubusercontent.com/4745cfb01a8919b4250e8e04cd8ac10673c2daa14c6bcb68bc83f126d3dc7759/68747470733a2f2f706f7365722e707567782e6f72672f7465636e69636b636f6d2f74632d6c69622d7064662d656e63727970742f646f776e6c6f616473)](https://packagist.org/packages/tecnickcom/tc-lib-pdf-encrypt)

[![Sponsor on GitHub](https://camo.githubusercontent.com/dd89cb32d6e7ff9dbb0fa7ce84923567358b220feb9198b3720beabc3153da6a/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73706f6e736f722d6769746875622d4541344141412e7376673f6c6f676f3d67697468756273706f6e736f7273266c6f676f436f6c6f723d7768697465)](https://github.com/sponsors/tecnickcom)

> 💖 Part of the [tc-lib-pdf / TCPDF](https://github.com/tecnickcom/tc-lib-pdf) ecosystem (100M+ installs). [Sponsor its maintenance →](https://github.com/sponsors/tecnickcom)

---

Overview
--------

[](#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 **License**[GNU LGPL v3](https://www.gnu.org/copyleft/lesser.html) - see [LICENSE](LICENSE)**API docs****Packagist**---

Security Notice
---------------

[](#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_DEPRECATED` notice 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.**

ModeAlgorithmSecurity0RC4-40**Broken — do not use**1RC4-128**Broken — do not use**2AES-128Acceptable for legacy compatibility3AES-256 R5 (PDF 1.7 ext.)Recommended4AES-256 R6 (PDF 2.0 / ISO 32000-2)Recommended (most current)---

Features
--------

[](#features)

### Encryption

[](#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`, `/EFF` dictionary entry)
- Public-key (certificate) encryption for multiple recipients

### Decryption

[](#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 to `encryptString()`

### Integration

[](#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
------------

[](#requirements)

- PHP 8.2 or later
- Extensions: `date`, `hash`, `openssl`, `pcre`
- Composer

---

Installation
------------

[](#installation)

```
composer require tecnickcom/tc-lib-pdf-encrypt
```

---

Quick Start
-----------

[](#quick-start)

### Encrypting a string

[](#encrypting-a-string)

```
