Skip to content
This repository has been archived by the owner on Dec 30, 2020. It is now read-only.

Commit

Permalink
Example added
Browse files Browse the repository at this point in the history
  • Loading branch information
Florent Morselli committed Dec 30, 2015
1 parent ab49070 commit 6ec39ef
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
* text=auto

/doc export-ignore
/examples export-ignore
/tests export-ignore
/.coveralls.yml export-ignore
/.scrutinizer.yml export-ignore
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
62 changes: 62 additions & 0 deletions examples/Load4.php
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.

0 comments on commit 6ec39ef

Please sign in to comment.