PHPackages                             tigr/laravel-compact-encrypter - 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. [Security](/categories/security)
4. /
5. tigr/laravel-compact-encrypter

ActiveLibrary[Security](/categories/security)

tigr/laravel-compact-encrypter
==============================

Encrypter for Laravel that produces much shorter output

1.0.3(2y ago)122MITPHPPHP ^7.0|^8.0

Since May 14Pushed 2y ago1 watchersCompare

[ Source](https://github.com/TiGR/laravel-compact-encrypter)[ Packagist](https://packagist.org/packages/tigr/laravel-compact-encrypter)[ RSS](/packages/tigr-laravel-compact-encrypter/feed)WikiDiscussions master Synced today

READMEChangelog (2)Dependencies (4)Versions (5)Used By (0)

URL-safe Compact Encrypter for Laravel
======================================

[](#url-safe-compact-encrypter-for-laravel)

[![Travis (.org)](https://camo.githubusercontent.com/9615d9c4f384a030c4c238853c2d916c7bc9efe92f070ede208050a8532de9ec/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f546947522f6c61726176656c2d636f6d706163742d656e637279707465722e737667)](https://camo.githubusercontent.com/9615d9c4f384a030c4c238853c2d916c7bc9efe92f070ede208050a8532de9ec/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f546947522f6c61726176656c2d636f6d706163742d656e637279707465722e737667)[![PHP from Packagist](https://camo.githubusercontent.com/98e06ab279ef7d8f5dc610b12861b445a427f985f0ced740b6982d8fac4b3fe8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e302532422d626c75652e737667)](https://camo.githubusercontent.com/98e06ab279ef7d8f5dc610b12861b445a427f985f0ced740b6982d8fac4b3fe8/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d372e302532422d626c75652e737667)[![Laravel Version](https://camo.githubusercontent.com/ae08e00c8a762d79ab7c5a25217d45e2fee1f9362b128c3d58c1d2576a283a9c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d352e352532422d626c75652e737667)](https://camo.githubusercontent.com/ae08e00c8a762d79ab7c5a25217d45e2fee1f9362b128c3d58c1d2576a283a9c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c61726176656c2d352e352532422d626c75652e737667)[![Packagist Version](https://camo.githubusercontent.com/4baea2170e866c05e2526674c062c66dc6346abb085094fede339236ae63934e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f546947522f6c61726176656c2d636f6d706163742d656e637279707465722e737667)](https://camo.githubusercontent.com/4baea2170e866c05e2526674c062c66dc6346abb085094fede339236ae63934e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f546947522f6c61726176656c2d636f6d706163742d656e637279707465722e737667)[![GitHub](https://camo.githubusercontent.com/ae5778f315859041b13436ae4730e42ddd124d3c348e54b6300b5752a0c6c77f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f546947522f6c61726176656c2d636f6d706163742d656e637279707465722e737667)](https://camo.githubusercontent.com/ae5778f315859041b13436ae4730e42ddd124d3c348e54b6300b5752a0c6c77f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f546947522f6c61726176656c2d636f6d706163742d656e637279707465722e737667)

Drop-in replacement for Laravel encrypter that produces much more concise and URL-safe output with fallback for encrypted data in old format. For Laravel 5.5+.

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

[](#installation)

```
composer require tigr/laravel-compact-encrypter

```

Then Laravel should do the magic and register our service provider.

Why?
----

[](#why)

Laravel's encrypter is very inefficient when it comes to space usage. It takes 64 bytes of raw encrypted data and converts it into 192 characters. How?

Laravel stores encrypted data in base64-encoded JSON containing base64 and HEX strings inside. So, `base64_encode(json_encode(base64_encode(data) + sha256 hex hash))`. Just compare encryption of simple string "hello":

```
# Laravel Encrypter: 192 characters long
$ artisan tinker
>>> Crypt::encryptString('hello')
=> "eyJpdiI6IlZRZFY5TVZiZVdNSlg3RVdDYTNDbHc9PSIsInZhbHVlIjoiNk9rXC9oV3hZaWEzNE95SU5xMUVHUWc9PSIsIm1hYyI6ImIyZDQ1MTdiODlhMzU1ZjQ1NmU3N2ZlN2I4OGU0Yzc2MjIyZDBkMzAwMGViNjM2OTFlMTZkOGY4MDFjYTg1NDIifQ=="

# add Compact Encrypter
$ composer require tigr/laravel-compact-encrypter

# Compact Encrypter: 70 characters long
$ artisan tinker
>>> Crypt::encryptString('hello')
=> "ABvcrldH1QNn8AgEL_LY-E_Cj04MRWPn3M-kSuvf3DAjzsNfFqC_lUml6iqGkRTjlox2kA"

# Compact Encrypter dropping verification hash: 53 characters long
>>> Crypt::encryptString('hello', false)
=> "z4zztewR8vQ7QId_P6diDRW2DvVPhwf4xh8gNss4G1o"

```

Who cares?
----------

[](#who-cares)

First, if you have some encrypted cookies, you might easily run into 400 errors with "header too long" from your server, or from load-balancing/DDoS-protection proxies in the middle. On average, Compact Encrypter produces 25-275% more compact output or up to 360% more compact with hash dropped.

Second, you might want to use self-contained tokens in URLs (no need for token DB), but guess what, 192 characters some of which are URL-escaped are way too ugly.

How does it work?
-----------------

[](#how-does-it-work)

1. No intermediate base64 or hex encoding, all data is raw binary.
2. No JSON, use pack()/unpack().
3. Use URL-safe version of base64 (drop trailing '=', replace '/+' with '-\_').
4. For hashing, use SHA1 instead of SHA256. I know, I know, but for real-world purposes SHA1 is still good enough.
5. Allow dropping Mac (validation hash) whatsoever in case you want it really short.
6. And provide fallback decryption if we ever encounter data encrypted with Laravel Encryptor

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

Established project with proven stability

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

Total

4

Last Release

1077d ago

PHP version history (2 changes)1.0.0PHP ^7.0

1.0.3PHP ^7.0|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/281226?v=4)[Igor Tarasov](/maintainers/TiGR)[@TiGR](https://github.com/TiGR)

---

Top Contributors

[![TiGR](https://avatars.githubusercontent.com/u/281226?v=4)](https://github.com/TiGR "TiGR (14 commits)")

---

Tags

encryption-supportencyptionlaravel

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tigr-laravel-compact-encrypter/health.svg)

```
[![Health](https://phpackages.com/badges/tigr-laravel-compact-encrypter/health.svg)](https://phpackages.com/packages/tigr-laravel-compact-encrypter)
```

###  Alternatives

[illuminate/encryption

The Illuminate Encryption package.

9229.7M280](/packages/illuminate-encryption)[spatie/laravel-ciphersweet

Use ciphersweet in your Laravel project

416718.4k1](/packages/spatie-laravel-ciphersweet)[ercsctt/laravel-file-encryption

Secure file encryption and decryption for Laravel applications

642.6k](/packages/ercsctt-laravel-file-encryption)[dgtlss/owaspadvisor

A Laravel package to help developers implement OWASP Top 10 security guidelines

327.1k](/packages/dgtlss-owaspadvisor)

PHPackages © 2026

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