diff --git a/.gitattributes b/.gitattributes index ea7be1e9..cc95b44d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,7 @@ * text=auto /doc export-ignore +/examples export-ignore /tests export-ignore /.coveralls.yml export-ignore /.scrutinizer.yml export-ignore diff --git a/Example/Encrypt1.php b/examples/Encrypt1.php similarity index 100% rename from Example/Encrypt1.php rename to examples/Encrypt1.php diff --git a/Example/Load1.php b/examples/Load1.php similarity index 100% rename from Example/Load1.php rename to examples/Load1.php diff --git a/Example/Load2.php b/examples/Load2.php similarity index 100% rename from Example/Load2.php rename to examples/Load2.php diff --git a/Example/Load3.php b/examples/Load3.php similarity index 100% rename from Example/Load3.php rename to examples/Load3.php diff --git a/examples/Load4.php b/examples/Load4.php new file mode 100644 index 00000000..8b0f60e3 --- /dev/null +++ b/examples/Load4.php @@ -0,0 +1,62 @@ + 'dir', + 'dir' => 'saH0gFSP4XM_tAP_a5rU9ooHbltwLiJpL4LLLnrqQPw', +]); + +// We store the key in a JWKSet object. +// This allow you to use multiple keys +$keyset = new JWKSet(); +$keyset = $keyset->addKey($shared_key); + +//The JWE +$input = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMjU2R0NNIiwia2lkIjoiTXkgU2hhcmVkIEtleSJ9..gqkq-9muWfQd3AHD.kg_fCtrkId7poGRCUP9ARO4KQ4m0R6lU5rwNS8Mm8nLFMy_X3nBC1VkL_zDehO4K6eEliZ9ISBEE7fFM6aFppfTCwFd_q-qikoOy7zsSeOOEawDZX2qMMdZYnaZs1HZTezdgS7HmoNK1J1TfE1PNrmhjrIZEbTANWw.Hxy5fTBX8X10_bz5UuDeBQ'; + + +/******************/ +/* SERVICES */ +/******************/ + +// The loader. This service will load the input and convert it into a JWS or JWE object +$loader = LoaderFactory::createLoader(); + +// The decrypter will try to decrypt a JWE object using private, shared or direct keys in the keyset +// We indicate the algorithms we want to use +$decrypter = DecrypterFactory::createDecrypter( + [ + 'dir', + 'A256GCM', + ] +); + +/******************/ +/* LET'S GO! */ +/******************/ + +// We load the input +$jwe = $loader->load($input); + +if (!$jwe instanceof JWEInterface) { + throw new \RuntimeException('Something went wrong'); +} + +// At this time the payload is null. +// We have to decrypt it +$is_decrypted = $decrypter->decrypt($jwe, $keyset); + +// The variable $is_decrypted contains a boolean that indicates the decryption succeeded or not. +// Now the $jwe object has a payload diff --git a/Example/Signature1.php b/examples/Signature1.php similarity index 100% rename from Example/Signature1.php rename to examples/Signature1.php diff --git a/Example/Signature2.php b/examples/Signature2.php similarity index 100% rename from Example/Signature2.php rename to examples/Signature2.php