JWTEncrypt
Method Signature
JWTEncrypt( payload, [key], [options] )Arguments
Argument
Type
Required
Description
Default
Options
Option
Type
Description
Default
Returns
Examples
// RSA key wrapping (asymmetric encryption)
token = jwtEncrypt( { sub: "u1", ssn: "123-45-6789" }, rsaPublicKeyPem, {
keyAlgorithm: "RSA-OAEP-256",
encAlgorithm: "A256GCM"
} );
// Direct symmetric encryption (32-byte key for A256GCM)
token = jwtEncrypt( { sub: "u1" }, secret32bytes, {
keyAlgorithm: "dir",
encAlgorithm: "A256GCM"
} );
// Nested JWT — sign first, then encrypt with cty: "JWT"
signed = jwtCreate( { sub: "u1" }, signingKey, "RS256" );
encrypted = jwtEncrypt( signed, encryptionPubKey, {
keyAlgorithm: "RSA-OAEP-256",
encAlgorithm: "A256GCM",
headers: { cty: "JWT" }
} );Related
Last updated
Was this helpful?
