JWT Framework
Search…
JWE decryption

JWE Decrypter Factory Service

A JWEDecrypterFactory is available as a service in your application container:
1
<?php
2
use Jose\Component\Encryption\JWEDecrypterFactory;
3
4
$jweDecrypterFactory = $container->get(JWEDecrypterFactory::class);
Copied!
With this factory, you will be able to create the JWEDecrypter you need:
1
$jweDecrypter = $jweDecrypterFactory->create(['HS256']);
Copied!
You can now use the JWEDecrypter as explained in the JWE Creation section.
Reminder: it is important to check the token headers. See the checker section of this documentation.

JWE Decrypter As Service

There is also another way to create a JWEDecrypter object: using the bundle configuration.
1
jose:
2
jwe:
3
decrypters:
4
decrypter1:
5
key_encryption_algorithms: ['A256GCMKW']
6
content_encryption_algorithms: ['A256CBC-HS256']
7
compression_methods: ['DEF']
8
is_public: true
Copied!
With the previous configuration, the bundle will create a public JWE Decrypter service named jose.jwe_decrypter.decrypter1 with selected encryption algorithms.
1
<?php
2
$jweDecrypter = $container->get('jose.jwe_decrypter.decrypter1');
Copied!

Custom Tags

This feature was introduced in version 1.1.
You can add custom tags and attributes to the services you create.
1
jose:
2
jwe:
3
decrypters:
4
decrypter1:
5
key_encryption_algorithms: ['A256GCMKW']
6
content_encryption_algorithms: ['A256CBC-HS256']
7
compression_methods: ['DEF']
8
tags:
9
tag_name1: ~
10
tag_name2: {attribute1: 'foo'}
Copied!

JWE Loader Service

The JWELoaderFactory is available as a public service. You can retrieve it using the container or inject it into your services. It will help you to create JWELoader objects on demand.
1
<?php
2
use Jose\Component\Encryption\JWELoaderFactory;
3
4
$jweLoaderFactory = $container->get(JWELoaderFactory::class);
Copied!
You can also create JWELoader objects as services using the configuration of the bundle.
1
jose:
2
jwe:
3
loaders:
4
jwe_loader1:
5
key_encryption_algorithms: ['A256GCMKW']
6
content_encryption_algorithms: ['A256CBC-HS256']
7
compression_methods: ['DEF']
8
header_checkers: ['alg', 'enc']
9
is_public: true
Copied!
Or using the ConfigurationHelper.
1
<?php
2
use Jose\Bundle\JoseFramework\Helper\ConfigurationHelper;
3
4
...
5
ConfigurationHelper::addJWELoader($container, 'jwe_loader1', ['jwe_compact'], ['A256GCMKW'], ['A256CBC-HS256'], ['DEF'], ['alg', 'enc'], true);
Copied!
Last modified 1yr ago