dev-master
9999999-dev https://github.com/bllohar/php-jwt-class-with-RSA-supportPHP Implementation of JSON Web token with RSA.
MIT
The Requires
- php >=5.3.0
by BL Lohar
jwt json web token php web token php jwt jwt token
PHP Implementation of JSON Web token with RSA.
PHP Implementation of JSON Web token with RSA., (*1)
I needed a JWT support for one client mobile application with RSA public/private keys., (*2)
I thought i should share with you all. Feel free to modify and use in your project., (*3)
Supported algos : RSA (Public Key/Private Key pair), (*4)
RS256 - RSA using SHA-256 hash algorithm RS384 - RSA using SHA-384 hash algorithm RS512 - RSA using SHA-512 hash algorithm HMAC Algos : HS256 - HMAC using SHA-256 hash algorithm (default) HS384 - HMAC using SHA-384 hash algorithm HS512 - HMAC using SHA-512 hash algorithm
With composer, (*5)
composer require bllohar/php-jwt-class-with-rsa-support ```` Or ##### git clone https://github.com/bllohar/php-jwt-class-with-RSA-support.git ```php include 'php-jwt-class-with-RSA-support/src/JWToken.php';
$payload = array( 'username' => 'bllohar', 'userId' => 1 ); //Please do not use key provided here in production they are just for demo. $private_key = file_get_contents('keys/private_key.pem'); $public_key = file_get_contents('keys/public_key.pem'); // Generate token with Private key $token = JWToken::encode($payload, $private_key,'RS256'); // Verifying the token try{ $data = JWToken::decode($token,$public_key,'RS256'); var_dump($data); }catch(Exception $e){ echo $e->getMessage(); }
$payload = array( 'username' => 'bllohar', 'userId' => 1 ); $secret = "^&562!2wzJGH!222"; // your secret key [should store in ENV variable] // Generate token with secret $token = JWToken::encode($payload, $secret,'HS512'); // Verifying the token try{ $data = JWToken::decode($token,$secret,'HS512'); var_dump($data); }catch(Exception $e){ echo $e->getMessage(); }
PHP Implementation of JSON Web token with RSA.
MIT
jwt json web token php web token php jwt jwt token