PHPackages                             deu7ex/stream-encryption - 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. deu7ex/stream-encryption

ActiveLibrary

deu7ex/stream-encryption
========================

PSR-7 stream encryption compatible with WhatsApp media format

02PHP

Since Jul 27Pushed 9mo agoCompare

[ Source](https://github.com/deu7ex/stream-encryption)[ Packagist](https://packagist.org/packages/deu7ex/stream-encryption)[ RSS](/packages/deu7ex-stream-encryption/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

Stream Encryption for PSR-7 Streams
===================================

[](#stream-encryption-for-psr-7-streams)

This Composer package implements encryption and decryption of PSR-7 streams using the same algorithm as WhatsApp for media files (image, audio, video, document).

Features
--------

[](#features)

- Encrypt and decrypt PSR-7 streams (AES-256-CBC + HMAC-SHA256)
- Supports media types: IMAGE, AUDIO, VIDEO, DOCUMENT
- Automatically generates 32-byte mediaKey if not provided
- Generates sidecar for streamable media (video/audio)
- CLI scripts for easy encryption/decryption
- Fully testable with PHPUnit

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

[](#installation)

```
composer require deu7ex/stream-encryption
```

Or using:

```
git clone git@github.com:deu7ex/stream-encryption.git
cd stream-encryption
composer install
```

File Permissions for `samples/`
-------------------------------

[](#file-permissions-for-samples)

To ensure the CLI and tests run correctly, the `samples/` directory must be readable and writable.

Recommended settings:

```
chmod 755 samples       # Folder: owner can write, others can read
chmod 644 samples/*     # Files: readable and writable by owner
```

Make sure the PHP process or terminal user has write access to this folder if you're generating `.encrypted`, `.key`, or `.sidecar` files.

Usage
-----

[](#usage)

### Encrypt a Stream (CLI)

[](#encrypt-a-stream-cli)

```
php encrypt.php path/to/input.file MEDIA_TYPE
```

- `MEDIA_TYPE` = IMAGE, AUDIO, VIDEO, DOCUMENT (default: VIDEO)

Example:

```
php encrypt.php samples/VIDEO.original VIDEO
```

This will generate:

- `samples/VIDEO.original.encrypted`
- `samples/VIDEO.original.key`
- `samples/VIDEO.original.sidecar` (for VIDEO/AUDIO)

---

### Decrypt a Stream (CLI)

[](#decrypt-a-stream-cli)

```
php decrypt.php path/to/file.encrypted path/to/file.key MEDIA_TYPE
```

Example:

```
php decrypt.php samples/VIDEO.original.encrypted samples/VIDEO.original.key VIDEO
```

This will generate:

- `samples/VIDEO.original.encrypted.decrypted`

---

Programmatic Usage
------------------

[](#programmatic-usage)

### Encrypt

[](#encrypt)

```
require 'vendor/autoload.php';

use GuzzleHttp\Psr7\Utils;
use StreamEncryption\EncryptingStream;

$stream = Utils::streamFor(file_get_contents('file.jpg'));
$mediaKey = file_get_contents('samples/VIDEO.key');
$enc = new EncryptingStream($stream, $mediaKey, 'IMAGE');

file_put_contents('file.encrypted', (string) $enc);
file_put_contents('file.key', $enc->getMediaKey());
```

### Decrypt

[](#decrypt)

```
require 'vendor/autoload.php';

use GuzzleHttp\Psr7\Utils;
use StreamEncryption\DecryptingStream;

$stream = Utils::streamFor(file_get_contents('file.encrypted'));
$key = file_get_contents('file.key');
$dec = new DecryptingStream($stream, $key, 'IMAGE');

file_put_contents('file.decrypted', (string) $dec);
```

---

Testing
-------

[](#testing)

Run PHPUnit tests:

```
vendor/bin/phpunit
```

Or using config:

```
vendor/bin/phpunit -c phpunit.xml.dist
```

License
-------

[](#license)

MIT

###  Health Score

17

—

LowBetter than 6% of packages

Maintenance40

Moderate activity, may be stable

Popularity2

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity16

Early-stage or recently created project

 Bus Factor1

Top contributor holds 57.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/78b3f8b78468213d1c061264f28a41b0343512e06353da4d7434234800aa0cf7?d=identicon)[deu7ex](/maintainers/deu7ex)

---

Top Contributors

[![AnsveryTools](https://avatars.githubusercontent.com/u/123080437?v=4)](https://github.com/AnsveryTools "AnsveryTools (4 commits)")[![deu7ex](https://avatars.githubusercontent.com/u/4214502?v=4)](https://github.com/deu7ex "deu7ex (3 commits)")

### Embed Badge

![Health badge](/badges/deu7ex-stream-encryption/health.svg)

```
[![Health](https://phpackages.com/badges/deu7ex-stream-encryption/health.svg)](https://phpackages.com/packages/deu7ex-stream-encryption)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
