Encryption (JWE)
Encrypt and decrypt JWTs using RSA-OAEP key wrap or direct symmetric encryption.
RSA Key Wrapping (Asymmetric)
keys = jwtGenerateKeyPair( "RS256" ); // 2048-bit RSA pair
// Encrypt with the public key (anyone can do this)
token = jwtEncrypt( { sub: "u1", ssn: "123-45-6789" }, keys.publicKey, {
keyAlgorithm: "RSA-OAEP-256",
encAlgorithm: "A256GCM"
} );
// Decrypt with the private key (only the holder can do this)
payload = jwtDecrypt( token, keys.privateKey, {
keyAlgorithm: "RSA-OAEP-256",
encAlgorithm: "A256GCM"
} );Direct Symmetric Encryption
Nested JWT (Sign → Encrypt)
Fluent Builder for JWE
Related
Last updated
Was this helpful?
