PHPackages                             jsq/psr6-encrypting-decorator - 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. [Caching](/categories/caching)
4. /
5. jsq/psr6-encrypting-decorator

AbandonedArchivedLibrary[Caching](/categories/caching)

jsq/psr6-encrypting-decorator
=============================

For when policy or paranoia prevent you from leaving sensitive cache entries unencrypted at rest.

0.3.0(9y ago)116Apache-2.0PHPPHP ^5.5|^7.0

Since Dec 31Pushed 9y ago1 watchersCompare

[ Source](https://github.com/jeskew/psr6-encrypting-decorator)[ Packagist](https://packagist.org/packages/jsq/psr6-encrypting-decorator)[ RSS](/packages/jsq-psr6-encrypting-decorator/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (6)Versions (6)Used By (0)

PSR-6 Cache Encrypter
=====================

[](#psr-6-cache-encrypter)

[![Build Status](https://camo.githubusercontent.com/20002a15474dee04107284f417fdfeb6b2c911b7f381eae16708774651fc8f42/68747470733a2f2f7472617669732d63692e6f72672f6a65736b65772f707372362d656e6372797074696e672d6465636f7261746f722e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/jeskew/psr6-encrypting-decorator)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/9a649213c6686edcd75c5bb99208cc4b320a39be8db4e31c38b609f9fb99682e/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a65736b65772f707372362d656e6372797074696e672d6465636f7261746f722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jeskew/psr6-encrypting-decorator/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/f4d910c095938b6284322a26a2989d16f706167465224804e71b633c9213dd76/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6a65736b65772f707372362d656e6372797074696e672d6465636f7261746f722f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/jeskew/psr6-encrypting-decorator/?branch=master)[![Apache 2 License](https://camo.githubusercontent.com/191025ebc9a4198e6764862e936dc727f322e154ebeadc9616eef7c9f0587f3e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6a73712f707372362d656e6372797074696e672d6465636f7261746f722e7376673f7374796c653d666c6174)](https://www.apache.org/licenses/LICENSE-2.0.html)[![Total Downloads](https://camo.githubusercontent.com/4cac5daac69cfe0edb3a449245e142d037ca39ab2f8ba663039b0b77c3e1d4f6/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6a73712f707372362d656e6372797074696e672d6465636f7261746f722e7376673f7374796c653d666c6174)](https://packagist.org/packages/jsq/psr6-encrypting-decorator)[![Author](https://camo.githubusercontent.com/297a2017c3c5d5b0f717bf17f2713cd12b5ba24945e861cf9af88e37d6bf50ce/687474703a2f2f696d672e736869656c64732e696f2f62616467652f617574686f722d406a7265736b65772d626c75652e7376673f7374796c653d666c61742d737175617265)](https://twitter.com/jreskew)

Having to encrypt your data at rest shouldn't keep you from using the open-source tools you know and love. If you have data that needs a higher degree of security than the rest of your cache, you can store and access it via an encrypting `PoolDecorator`.

Caveats
-------

[](#caveats)

Encryption and decryption are both expensive operations, and frequent reads from an encrypted data store can quickly become a bottleneck in otherwise performant applications. Use encrypted caches sparingly.

Usage
-----

[](#usage)

> This package provides two cache decorators, one that encrypts data using a pass phrase and one that does so with a key pair.

First, create your PSR-6 cache as you normally would, then wrap your cache with an encrypting decorator:

```
$encryptedCache = new \Jsq\CacheEncryption\Password\PoolDecorator(
    $cache, // an instance of \Psr\Cache\CacheItemPoolInterface
    $password,
    $cipher // optional, defaults to 'aes-256-cbc'
);
```

Then use your `$cache` and `$encryptedCache` like you normally would:

```
$cache->save($cache->getItem('normal_cache_data')->set('Totally normal!'));

$encryptedCache->save($encryptedCache->getItem('api_key')->set('super_secret'));
```

Though your regular cache and encrypted cache share a storage layer and a keyspace, they will not be able to read each other's data. The `$encryptedCache`will return `false` for `isHit` if the underlying data is not encrypted, and the regular `$cache` will return gibberish if asked to read encrypted data.

```
var_dump($encryptedCache->getItem('api_key')->get());
// string(12) "super_secret"

var_dump($cache->getItem('api_key')->get());
// class Jsq\CacheEncryption\Password\EncryptedValue#177 (4) {
//     private $mac =>
//     string(64)
//     private $cipherText =>
//     string(44)
//     private $method =>
//     string(11) "aes-256-cbc"
//     private $initializationVector =>
//     string(16)
// }

var_dump($cache->getItem('normal_cache_data')->isHit());
// bool(true)

var_dump($encryptedCache->getItem('normal_cache_data')->isHit());
// bool(false)
```

Encrypting your cache with a key pair
-------------------------------------

[](#encrypting-your-cache-with-a-key-pair)

If you'd rather not rely on a shared password, the `Envelope\PoolDecorator`can secure your sensitive cache entries using a public/private key pair.

```
$encryptedCache = new \Jsq\CacheEncryption\Envelope\PoolDecorator(
    $cache,
    'file:///path/to/certificate.pem',
    'file:///path/to/private/key.pem',
    $passphrase_for_private_key_file, // optional, defaults to null
    $cipher // optional, defaults to 'aes-256-cbc'
);
```

> The certificate can be a valid x509 certificate, a path to a PEM-encoded certificate file (the path must be prefaced with `file://`), or a PEM-encoded certificate string. The private key can be a path to a PEM-encoded private key file (the path must be prefaced with `file://`), or a PEM-encoded certificate string.

Encrypting your cache as Iron tokens
------------------------------------

[](#encrypting-your-cache-as-iron-tokens)

This library also supports encryption compatible with the [Iron](https://github.com/hueniverse/iron) library. This can be useful if you would like to share a cache between multiple applications, even ones written in different languages. The Iron specification details how to seal JSON objects, so the Iron decorator will encode data passed to it as JSON before encrypting it. Decrypted items will be returned as arrays.

###  Health Score

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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.

###  Release Activity

Cadence

Every ~72 days

Total

3

Last Release

3641d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.5

0.2.0PHP ^5.5|^7.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/76a37eaa8fb7a04df094d25e1b53a908621faa9961da919f50c1c6c762ffbdfe?d=identicon)[jeskew](/maintainers/jeskew)

---

Top Contributors

[![jeskew](https://avatars.githubusercontent.com/u/705500?v=4)](https://github.com/jeskew "jeskew (18 commits)")

---

Tags

psrcachepsr-6

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jsq-psr6-encrypting-decorator/health.svg)

```
[![Health](https://phpackages.com/badges/jsq-psr6-encrypting-decorator/health.svg)](https://phpackages.com/packages/jsq-psr6-encrypting-decorator)
```

###  Alternatives

[psr/cache

Common interface for caching libraries

5.2k686.9M1.3k](/packages/psr-cache)[laminas/laminas-cache

Caching implementation with a variety of storage options, as well as codified caching strategies for callbacks, classes, and output

1076.9M130](/packages/laminas-laminas-cache)[cache/adapter-common

Common classes for PSR-6 adapters

11124.4M38](/packages/cache-adapter-common)[cache/tag-interop

Framework interoperable interfaces for tags

10525.0M12](/packages/cache-tag-interop)[cache/hierarchical-cache

A helper trait and interface to your PSR-6 cache to support hierarchical keys.

6016.1M11](/packages/cache-hierarchical-cache)[cache/filesystem-adapter

A PSR-6 cache implementation using filesystem. This implementation supports tags

705.8M82](/packages/cache-filesystem-adapter)

PHPackages © 2026

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