This repository has been archived by the owner on Dec 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Florent Morselli
committed
Dec 30, 2015
1 parent
ab49070
commit 6ec39ef
Showing
8 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
require_once __DIR__.'/../vendor/autoload.php'; | ||
|
||
use Jose\Factory\LoaderFactory; | ||
use Jose\Factory\DecrypterFactory; | ||
use Jose\Object\JWEInterface; | ||
use Jose\Object\JWK; | ||
use Jose\Object\JWKSet; | ||
|
||
/******************/ | ||
/* INPUT DATA */ | ||
/******************/ | ||
|
||
// My direct key. | ||
$shared_key = new JWK([ | ||
'kty' => '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 |
File renamed without changes.
File renamed without changes.