Skip to content

An implementation of the Fernet token specification in PHP

License

Notifications You must be signed in to change notification settings

webonyx/php-fernet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP-Fernet

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 msgpack wrapper to reduce token size
  • Key rotation (TBD)

Requirements

  • PHP 5.6 or later
  • hash extension
  • openssl or mcrypt extension
  • mbstring.func_overload needs to be switched off in php.ini

Installation

You can install via Composer.

{
    "require": {
        "webonyx/php-fernet": "dev-master"
    }
}

Usage

<?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';
}
?>

License

BSD 3 clause

About

An implementation of the Fernet token specification in PHP

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages