PHPackages                             decodelabs/cipher - 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. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. decodelabs/cipher

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

decodelabs/cipher
=================

Tools and systems to interact with JWTs

v0.3.1(7mo ago)150811MITPHPPHP ^8.4CI passing

Since Nov 27Pushed 5mo ago2 watchersCompare

[ Source](https://github.com/decodelabs/cipher)[ Packagist](https://packagist.org/packages/decodelabs/cipher)[ RSS](/packages/decodelabs-cipher/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (10)Dependencies (8)Versions (14)Used By (1)

Cipher
======

[](#cipher)

[![PHP from Packagist](https://camo.githubusercontent.com/9046bca639fca55ed488a20eb81e5fe2302aa49c7dd3c2ac230d1218cf13b49a/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f6465636f64656c6162732f6369706865723f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/cipher)[![Latest Version](https://camo.githubusercontent.com/aefe2ff99403c72d9e270df8b5d65f5524efc489a1b1dd59b50d1092582e8074/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6465636f64656c6162732f6369706865722e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/cipher)[![Total Downloads](https://camo.githubusercontent.com/15ddffb304aa24a118421909465c129235433fe6b5fb53a334f0b81fdabde3ad/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6465636f64656c6162732f6369706865722e7376673f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/cipher)[![GitHub Workflow Status](https://camo.githubusercontent.com/f77ee6aaba8504c993881bbfc720b5bed42076fc694efc3ddea1d51014102ca1/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f6465636f64656c6162732f6369706865722f696e746567726174652e796d6c3f6272616e63683d646576656c6f70)](https://github.com/decodelabs/cipher/actions/workflows/integrate.yml)[![PHPStan](https://camo.githubusercontent.com/e25c14ce011edabdd0fbd2e10415b41cc5d66ed11ef3e5b7edd074c5bdd35a2d/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d656e61626c65642d3434434331312e7376673f6c6f6e6743616368653d74727565267374796c653d666c6174)](https://github.com/phpstan/phpstan)[![License](https://camo.githubusercontent.com/441c8cb228ff0ccc8e82205b731028145ac4fd9ea5d1deb4a1afc9e579b22569/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6465636f64656c6162732f6369706865723f7374796c653d666c6174)](https://packagist.org/packages/decodelabs/cipher)

### Tools and systems to interact with JWTs

[](#tools-and-systems-to-interact-with-jwts)

Cipher provides an integrated suite of tools for working with JWTs, including a simple interface for creating and verifying tokens, and a set of middleware for use with [Harvest](https://github.com/decodelabs/harvest), [Greenleaf](https://github.com/decodelabs/greenleaf), or any other PSR-15 compatible middleware stack.

---

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

[](#installation)

This package requires PHP 8.4 or higher.

Install via Composer:

```
composer require decodelabs/cipher
```

Usage
-----

[](#usage)

### Codec

[](#codec)

The `Codec` class provides the means to encode and decode JWTs. The class requires an instance of `DecodeLabs\Cipher\Config` to be passed to the constructor - we provide a default [Dovetail](https://github.com/decodelabs/dovetail) implementation for this, but you can use your own if you wish.

The config defines what secret and algorithm is used.

```
use DecodeLabs\Cipher\Codec;
use DecodeLabs\Dovetail;
use DecodeLabs\Monarch;

$dovetail = Monarch::getService(Dovetail::class);
$config = $dovetail->load('Cipher');
$codec = new Codec($config);

$payload = $codec->decode($token);
```

### Payload

[](#payload)

The `Payload` interface defines a simple wrapper around JWT payload data with `ArrayAccess` support. The `Factory` will instantiate a `Generic` payload for unrecognized issuers, however extended implementations for specific issuers can be created and used instead, providing formal access to custom claim data.

```
// $payload['iss'] = 'https://abcdefg.supabase.co/auth/v1'
// $payload instance of DecodeLabs\Cipher\Payload\Supabase
$email = $payload->getEmail();
$provider = $payload->getProvider();
```

### Middleware

[](#middleware)

Cipher provides a set of middleware for use with [Harvest](https://github.com/decodelabs/harvest) or [Greenleaf](https://github.com/decodelabs/greenleaf), or any other PSR-15 compatible middleware stack.

With the Middleware in your PSR-15 stack, Cipher will attempt to load a JWT from the request, and if successful, will set the `jwt.payload` attribute on the request with the decoded payload.

```
$payload = $request->getAttribute('jwt.payload');
```

If using [Greenleaf](https://github.com/decodelabs/greenleaf), the payload can be injected into your action automatically via [Slingshot](https://github.com/decodelabs/slingshot), (below example uses `Supabase` payload):

```
use DecodeLabs\Cipher\Payload\Supabase;
use DecodeLabs\Greenleaf\Action;
use DecodeLabs\Greenleaf\Action\ByMethodTrait;
use DecodeLabs\Harvest\Response\Json as JsonResponse;

class MySecureAction implements Action
{
    use ByMethodTrait;

    public const Middleware = [
        'Jwt' => [
            'required' => true
        ]
    ];

    public function get(
        Supabase $payload,
    ): JsonResponse {
        return new JsonResponse([
            'email' => $payload->getEmail()
        ]);
    }
}
```

Licensing
---------

[](#licensing)

Cipher is licensed under the MIT License. See [LICENSE](./LICENSE) for the full license text.

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance67

Regular maintenance activity

Popularity15

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity57

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 ~61 days

Recently: every ~33 days

Total

12

Last Release

227d ago

PHP version history (2 changes)v0.1.0PHP ^8.1

v0.2.0PHP ^8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/8a241d64d12b3b5ee94197862ec1ec30b82ed2efa34a0cd7f4c3565a021daddd?d=identicon)[betterthanclay](/maintainers/betterthanclay)

---

Top Contributors

[![betterthanclay](https://avatars.githubusercontent.com/u/1273586?v=4)](https://github.com/betterthanclay "betterthanclay (57 commits)")

---

Tags

jwtmiddlewarephppsr-15

### Embed Badge

![Health badge](/badges/decodelabs-cipher/health.svg)

```
[![Health](https://phpackages.com/badges/decodelabs-cipher/health.svg)](https://phpackages.com/packages/decodelabs-cipher)
```

###  Alternatives

[google/auth

Google Auth Library for PHP

1.4k272.7M162](/packages/google-auth)[thenetworg/oauth2-azure

Azure Active Directory OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2509.6M48](/packages/thenetworg-oauth2-azure)[stevenmaguire/oauth2-keycloak

Keycloak OAuth 2.0 Client Provider for The PHP League OAuth2-Client

2275.9M27](/packages/stevenmaguire-oauth2-keycloak)[robsontenorio/laravel-keycloak-guard

🔑 Simple Keycloak Guard for Laravel

5161.1M3](/packages/robsontenorio-laravel-keycloak-guard)[patrickbussmann/oauth2-apple

Sign in with Apple OAuth 2.0 Client Provider for The PHP League OAuth2-Client

1132.5M6](/packages/patrickbussmann-oauth2-apple)[wp-graphql/wp-graphql-jwt-authentication

JWT Authentication for WPGraphQL

361118.4k1](/packages/wp-graphql-wp-graphql-jwt-authentication)

PHPackages © 2026

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