Encrypted Tokens (JWE)
The JWE object, encryption algorithms and token serializers are part of the encryption component (web-token/jwt-encryption). Claim and header checkers are decoupled and can be found in the checker component (web-token/jwt-checker).
Why are encryption and checker components not together? The main reason is that when you issue encrypted tokens, you do not need any checker. Those components are decoupled to avoid the installation of unnecessary files.
The encryption and decryption processes have been completely reviewed.
In the examples below, we suppose we already have a JWK object ($key).
Encryted Tokens Creation
Before
<?php
use Jose\Factory\JWEFactory;
use Jose\Factory\JWKFactory;
// We want to encrypt a very important message
$message = 'Today, 8:00PM, train station.';
$jwe = JWEFactory::createJWEToCompactJSON(
$message, // The message to encrypt
$key, // The key of the recipient
[ // The shared protected header
'alg' => 'RSA-OAEP-256',
'enc' => 'A256CBC-HS512',
'zip' => 'DEF',
]
);After
Tokens Decryption
Before
After
Please note that it is important to check the token header before the decryption of the token. It will help you to reject tokens signed with unsupported algorithms or for other audiences.
Last updated
Was this helpful?