Fernet-PHP implementation of the Fernet token specification in PHP. This is a fork of Kelvinmo implementation at fernet-php with some improvements:
- Drop supporting old PHP versions
- Exception base for error handling
- Support
msgpackwrapper to reduce token size - Key rotation (TBD)
- PHP 5.6 or later
hashextensionopensslormcryptextensionmbstring.func_overloadneeds to be switched off inphp.ini
You can install via Composer.
{
"require": {
"webonyx/php-fernet": "dev-master"
}
}<?php
require 'vendor/autoload.php';
use Fernet\Fernet;
use Fernet\InvalidTokenException;
$key = '[Base64url encoded fernet key]'; // or $key = Fernet::generateKey();
$fernet = new Fernet($key); // or new FernetMsgpack($key);
$token = $fernet->encode('string message');
try {
$message = $fernet->decode('fernet token');
} catch (InvalidTokenException $exception) {
echo 'Token is not valid';
}
?>BSD 3 clause