free2er/jwt

JWT tools

1.0.0 2020-03-17 15:21 UTC

This package is auto-updated.

Last update: 2024-11-18 01:40:02 UTC


README

JWT tools

Installation

This component can be installed with the Composer dependency manager.

  1. Install Composer

  2. Install the component as a dependency of your project

     composer require free2er/jwt
    

Usage

Create JWK

use Free2er\Jwt\KeyFactory;

$factory = new KeyFactory();
$factory->create('/path/to/private.key');
$factory->create('/path/to/public.key');

Create JWT

use Free2er\Jwt\TokenFactory;

$factory = new TokenFactory();
$factory->create(['aud' => 'client', 'sub' => 'user'], '/path/to/private.key');

Validate JWT

use Free2er\Jwt\TokenValidator;

$validator = new TokenValidator();
$validator->validate('some.jwt.token', '/path/to/public.key');

OpenSSL commands

Generate RSA keys

openssl genrsa -out private.key 2048
openssl rsa -in private.key -pubout -out public.key

Generate RSA keys with password

openssl genrsa -passout pass:_passphrase_ -out private.key 2048
openssl rsa -in private.key -passin pass:_passphrase_ -pubout -out public.key

Generate EC P-256 keys

openssl ecparam -name prime256v1 -genkey -noout -out private.key
openssl ec -in private.key -pubout -out public.key

Generate EC P-384 keys

openssl ecparam -name secp384r1 -genkey -noout -out private.key
openssl ec -in private.key -pubout -out public.key

Generate EC P-521 keys

openssl ecparam -name secp521r1 -genkey -noout -out private.key
openssl ec -in private.key -pubout -out public.key

Generate Ed25519 keys

openssl genpkey -algorithm Ed25519 -out private.key
openssl pkey -in private.key -pubout -out public.key