1. Go to this page and download the library: Download kelvinmo/simplejwt library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
kelvinmo / simplejwt example snippets
$set = new SimpleJWT\Keys\KeySet();
$set->load(file_get_contents('private.json'));
$set = new SimpleJWT\Keys\KeySet();
// JWK format
$key = new SimpleJWT\Keys\RSAKey(file_get_contents('jwk.json'), 'json');
// PEM format - note raw key only, no X.509 certificates
$key = new SimpleJWT\Keys\RSAKey(file_get_contents('rsa.pem'), 'pem');
$set->add($key);
$set = SimpleJWT\Keys\KeySet::createFromSecret('secret123');
// The above is a shortcut for the following:
$set = new SimpleJWT\Keys\KeySet();
$key = new SimpleJWT\Keys\SymmetricKey('secret123', 'bin');
$set->add($key);
try {
$result = SimpleJWT\JWT::deserialise('abc.def.ghigjghr');
} catch (SimpleJWT\InvalidTokenException $e) {
}
print $result['claims']['sub'];
print $result['signatures'][0]['headers']['alg'];
print $result['signatures'][0]['signing_input']; // abc.def
print $result['signatures'][0]['signature']; // ghigjghr
// Additional indices under $result['signatures'] if the JWT has more than
// one signature
// Note $headers['alg'] and $headers['enc'] are ' => 'A128CBC-HS256'];
$plaintext = 'This is the plaintext I want to encrypt.';
$jwt = new SimpleJWT\JWE($headers, $plaintext);