From 293a6589ee63a35ab4625448a3c12abc4f6085b5 Mon Sep 17 00:00:00 2001 From: Milad Rahimi Date: Fri, 25 Nov 2022 15:56:28 +0330 Subject: [PATCH] Update README.md --- README.md | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6e013ea..15148cc 100644 --- a/README.md +++ b/README.md @@ -76,24 +76,23 @@ use MiladRahimi\Jwt\Cryptography\Keys\RsaPublicKey; use MiladRahimi\Jwt\Generator; use MiladRahimi\Jwt\Parser; +// Generate a token $privateKey = new RsaPrivateKey('/path/to/private.pem'); -$publicKey = new RsaPublicKey('/path/to/public.pem'); - $signer = new RS256Signer($privateKey); -$verifier = new RS256Verifier($publicKey); - -// Generate a token $generator = new Generator($signer); $jwt = $generator->generate(['id' => 666, 'is-admin' => true]); // Parse the token +$publicKey = new RsaPublicKey('/path/to/public.pem'); +$verifier = new RS256Verifier($publicKey); $parser = new Parser($verifier); $claims = $parser->parse($jwt); -echo $claims; // ['id' => 666, 'is-admin' => true] +print_r($claims); // ['id' => 666, 'is-admin' => true] ``` -You can read [this instruction](https://en.wikibooks.org/wiki/Cryptography/Generate_a_keypair_using_OpenSSL) to learn how to generate a pair (public/private) RSA key. +You can read [this instruction](https://en.wikibooks.org/wiki/Cryptography/Generate_a_keypair_using_OpenSSL) +to learn how to generate a pair (public/private) RSA key. ### Validation