Encryption Algorithms
This framework comes with several encryption algorithms. These algorithms are in the following namespaces:
Jose\Component\Encryption\Algorithm\KeyEncryption: key encryption algorithmsJose\Component\Encryption\Algorithm\ContentEncryption: content encryption algorithmsFrom v1.2, the algorithms have their own sub-packages. To avoid BC breaks, these packages are automatically installed for all v1.x of the framework. Starting at v2.0, you will have to explicitly install the algorithm packages you need.
Key Encryption
Package
web-token/jwt-encryption-algorithm-aeskwA128KWA192KWA256KW
Package
web-token/jwt-encryption-algorithm-aesgcmkwA128GCMKWA192GCMKWA256GCMKW
Package
web-token/jwt-encryption-algorithm-dirdir(classDir)
Package
web-token/jwt-encryption-algorithm-ecdh-esECDH-ES(classECDHES) READ THE NOTE BELOWECDH-ES+A128KW(classECDHESA128KW) READ THE NOTE BELOWECDH-ES+A192KW(classECDHESA192KW) READ THE NOTE BELOWECDH-ES+A256KW(classECDHESA256KW) READ THE NOTE BELOW
Package
web-token/jwt-encryption-algorithm-pbes2PBES2-HS256+A128KW(classPBES2HS256A128KW)PBES2-HS384+A192KW(classPBES2HS384A192KW)PBES2-HS512+A259KW(classPBES2HS512A1256KW)
Package
web-token/jwt-encryption-algorithm-rsaRSA1_5(classRSA15) READ THE NOTE BELOWRSA-OAEP(classRSAOAEP)RSA-OAEP-256(classRSAOAEP256)
Content Encryption
Package
web-token/jwt-encryption-algorithm-aesgcmA128GCMA192GCMA256GCM
Package
web-token/jwt-encryption-algorithm-aescbcA128CBC-HS256(classA128CBCHS256)A192CBC-HS384(classA192CBCHS384)A256CBC-HS512(classA256CBCHS512)
IMPORTANT NOTE:
The algorithm
RSA1_5is deprecated due to known security vulnerability.The algorithms
ECDH-ES*are not recommended unless used with theOKPkey type.
The following signature algorithms are experimental and must not be used in production unless you know what you are doing. They are proposed for testing purpose only.
They are all part of the package web-token/jwt-encryption-algorithm-experimental
Key Encryption
A128CTR,A192CTRandA256CTR: AES CTR based encryption.Chacha20+Poly1305: Please note that this algorithm requires OpenSSL 1.1RSA-OAEP-384andRSA-OAEP-512: Same algorithm as RSA-OAEP-256 but with SHA-384 and SHA-512 hashing functions.
Content Encryption
AxxxCCM-16-128,AxxxCCM-16-64,AxxxCCM-64-128,AxxxCCM-64-64: AES-CCM based aalgorithms. xxx can be 128 or 256.
How To Use
These algorithms have to be used with the Algorithm Manager. They do not need any arguments.
Example:
<?php
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Encryption\Algorithm\KeyEncryption\A128KW;
use Jose\Component\Encryption\Algorithm\KeyEncryption\PBES2HS256A128KW;
use Jose\Component\Encryption\Algorithm\ContentEncryption\A128CBCHS256;
$algorithmManager = AlgorithmManager::create([
    new A128KW(),
    new PBES2HS256A128KW(),
    new A128CBCHS256(),
]);By default, PBES2* algorithms use the following parameter values:
Salt size: 64 bytes (512 bits)
Count: 4096
You may need to use other values. This can be done during the instantiation of the algorithm:
Example with 16 bytes (128 bits) salt and 1024 counts:
<?php
use Jose\Component\Core\AlgorithmManager;
use Jose\Component\Encryption\Algorithm\KeyEncryption\PBES2HS256A128KW;
$algorithmManager = AlgorithmManager::create([
    new PBES2HS256A128KW(16, 1024),
]);Last updated
Was this helpful?