PHPackages                             dvv/macaron - 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. dvv/macaron

ActiveLibrary[Security](/categories/security)

dvv/macaron
===========

Secure Signed Encrypted Tokens for PHP

1.2(9y ago)3153MITPHPPHP &gt;=5.4.0

Since Oct 28Pushed 6y ago1 watchersCompare

[ Source](https://github.com/dvv/macaron)[ Packagist](https://packagist.org/packages/dvv/macaron)[ Docs](https://github.com/dvv/macaron)[ RSS](/packages/dvv-macaron/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (4)Used By (0)

[![Build Status](https://camo.githubusercontent.com/350733c67e5073ba1fe2ef7702f5120b56ef0f7332177e791806917c632bfd67/68747470733a2f2f7472617669732d63692e6f72672f6476762f6d616361726f6e2e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/dvv/macaron)

Expiring Signed Encrypted Tokens for PHP
========================================

[](#expiring-signed-encrypted-tokens-for-php)

Library for serializing PHP-serializable data to signed encrypted strings and reliably deserializing them back.

Basically a port of my [Termit](https://github.com/dvv/termit) library.

Now stopped using `mcrypt` extension, see [here](https://wiki.php.net/rfc/mcrypt-viking-funeral).

Usage
-----

[](#usage)

```
// everlasting token
$token = \Macaron\Macaron::encode('whatever PHP can serialize', 'ver1STrongsikret');
echo \Macaron\Macaron::decode($token, 'ver1STrongsikret');
// 'whatever PHP can serialize'

echo \Macaron\Macaron::decode($token . 'FORGED!', 'ver1STrongsikret');
// false
echo \Macaron\Macaron::decode($token, 'ver1STrongsikret' . 'LEAKED!');
// false
```

```
// expiring token
$token = \Macaron\Macaron::encode('whatever PHP can serialize', $secret, '+3 seconds');
echo \Macaron\Macaron::decode($token, 'ver1STrongsikret');
// 'whatever PHP can serialize'

sleep(3);
echo \Macaron\Macaron::decode($token, 'ver1STrongsikret');
// null
```

```
// overriding serializer
class Pasta extends \Macaron\Macaron {

  static protected function serialize($data) {
    return json_encode($data);
  }

  static protected function unserialize($string) {
    return json_decode($string, true);
  }

}

$token = Pasta::encode('whatever JSON can contain', $secret, '+3 seconds');
echo Pasta::decode($token, 'ver1STrongsikret');
// 'whatever JSON ca contain'

sleep(3);
echo Pasta::decode($token, 'ver1STrongsikret');
// null
```

See tests for more.

License
-------

[](#license)

The MIT License (MIT)

Copyright © 2015 Vladimir Dronnikov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity60

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

Total

3

Last Release

3380d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/bd23e3fd6b9eb6d1e29968b38bee03857e00b135c33cd9fe28b294b2179e6d72?d=identicon)[dvv](/maintainers/dvv)

---

Top Contributors

[![dvv](https://avatars.githubusercontent.com/u/211335?v=4)](https://github.com/dvv "dvv (9 commits)")

---

Tags

tokensecuresessioncookiesigned

### Embed Badge

![Health badge](/badges/dvv-macaron/health.svg)

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

###  Alternatives

[aidantwoods/secureheaders

A PHP class aiming to make the use of browser security features more accessible.

433689.3k2](/packages/aidantwoods-secureheaders)[aura/session

Provides session management functionality, including lazy session starting, session segments, next-request-only ("flash") values, and CSRF tools.

2041.2M69](/packages/aura-session)[paragonie/anti-csrf

Paragon Initiative's Anti-CSRF Security Library

307200.6k5](/packages/paragonie-anti-csrf)[devrabiul/laravel-cookie-consent

A GDPR-compliant cookie consent solution for Laravel applications with fully customizable cookie banners, granular consent control, and enterprise-grade compliance features.

17633.8k1](/packages/devrabiul-laravel-cookie-consent)[kelvinmo/fernet-php

An implementation of the Fernet token specification in PHP.

211.7M3](/packages/kelvinmo-fernet-php)[kunststube/csrfp

A signed token generator for cross site request forgery protection.

52209.5k1](/packages/kunststube-csrfp)

PHPackages © 2026

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