JWT Framework
Search…
JWE creation

JWE Builder Factory Service

A JWEBuilderFactory is available as a service in your application container:
1
<?php
2
use Jose\Component\Encryption\JWEBuilderFactory;
3
4
$jweBuilderFactory = $container->get(JWEBuilderFactory::class);
Copied!
With this factory, you will be able to create the JWEBuilder you need:
1
$jweBuilder = $jweBuilderFactory->create(
2
['A256GCMKW'],
3
['A256CBC-HS256'],
4
['DEF'] // Compression methods
5
);
Copied!
Available compression methods are:
    DEF: deflate (recommended)
    GZ: gzip
    ZLIB: zlib
You can now use the JWEBuilder as explained in the JWE Creation section.

JWE Builder As Service

There is also another way to create a JWEBuilder object: using the bundle configuration.
1
jose:
2
jwe:
3
builders:
4
builder1:
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 Builder service named jose.jwe_builder.builder1 with selected encryption algorithms.
1
<?php
2
$jweBuilder = $container->get('jose.jwe_builder.builder1');
Copied!

Custom Tags

You can add custom tags and attributes to the services you create.
1
jose:
2
jwe:
3
builders:
4
builder1:
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!
Last modified 1yr ago