Skip to main content

JWE Encryption

The JWE Encryption endpoint detokenizes an outbound, client-initiated payload and encrypts the result as a JWE (JSON Web Encryption) compact token using RSA public key encryption. This enables secure transmission of sensitive data to downstream systems that accept JWE-formatted payloads.

Endpoint

Test URI: https://test-tgapi.tokenex.com/Crypto/EncryptJWE
Prod URI: https://tgapi.tokenex.com/Crypto/EncryptJWE

Supported HTTP Methods: POST

Authentication

This endpoint uses the same authentication mechanism as other client-initiated TGAPI endpoints. Supply your TokenEx ID and API key as HTTP header values.

HeaderDescriptionRequired
tx-tokenex-idID from the configuration menu in the client portalYes
tx-apikeyAPI key from the configuration menu in the client portalYes

Request Headers

In addition to the authentication headers, the following header is required:

HeaderDescriptionRequired
tx-jweoptionsBase64-encoded JSON object containing JWE encryption parameters (see below)Yes

Standard detokenization headers are also supported:

HeaderDescriptionRequired
tx-request-regexRegular expression to locate tokens in the request body (alternative to triple-brace notation)No
tx-cachecvvExtends the life of a security code for 5 minutes after initial useNo

TX-JWEOptions Header

The tx-jweoptions header value must be a Base64-encoded JSON object with the following fields:

FieldTypeDescription
algrequiredstring
one of: [RSA-OAEP, RSA-OAEP-256, RSA1_5]
Key management algorithm. Case-insensitive.
encrequiredstring
one of: [A128GCM, A192GCM, A256GCM, A128CBC-HS256, A192CBC-HS384, A256CBC-HS512]
Content encryption method. Case-insensitive.
publicKeyoptionalstring?RSA public key in PEM format. If omitted, the customer's encryption profile key is used.
kidoptionalstring?Key ID included in the JWE protected header
additionalHeadersoptionalobject?Additional headers included in the JWE protected header

Supported Algorithms (alg)

ValueDescription
RSA-OAEPRSA-OAEP using default parameters
RSA-OAEP-256RSA-OAEP using SHA-256 and MGF1 with SHA-256
RSA1_5

RSAES-PKCS1-v1_5

warning
Included for backward compatibility only. Prefer RSA-OAEP or RSA-OAEP-256 for new integrations.

Supported Encryption Methods (enc)

ValueDescription
A128GCMAES GCM using 128-bit key
A192GCMAES GCM using 192-bit key
A256GCMAES GCM using 256-bit key
A128CBC-HS256AES-CBC using 128-bit key with HMAC SHA-256
A192CBC-HS384AES-CBC using 192-bit key with HMAC SHA-384
A256CBC-HS512AES-CBC using 256-bit key with HMAC SHA-512

Building the Header Value

  1. Construct a JSON object with the desired options:

    {
    "alg": "RSA-OAEP-256",
    "enc": "A256GCM",
    "publicKey": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqh...\n-----END PUBLIC KEY-----"
    }
  2. Base64-encode the JSON string. The resulting value is used as the tx-jweoptions header.

Request Body

The request body follows the same format as the Transparent Detokenization endpoint. Tokens are wrapped in triple curly braces and functions use quadruple curly braces.

The endpoint detokenizes all tokens first, then JWE-encrypts the entire resulting payload.

Examples

POST https://test-tgapi.tokenex.com/Crypto/EncryptJWE HTTP/1.1
Content-Type: application/json
TX-TokenEx-ID: YourTokenExID
TX-APIKey: YourAPIKey
TX-JWEOptions: eyJhbGciOiJSU0EtT0FFUC0yNTYiLCJlbmMiOiJBMjU2R0NNIiwicHVibGljS2V5IjoiLS0tLS1CRUdJTi4uLiJ9

{
"card": "{{{545454tEc3Hk5454}}}",
"cvv": "{{{{FUNCTION:CVV,TOKEN:545454tEc3Hk5454}}}}",
"merchant": "test-merchant"
}

Public Key Options

The RSA public key used for encryption can be supplied in one of two ways:

  1. Inline via publicKey field — Include the PEM-encoded RSA public key directly in the tx-jweoptions JSON. This is useful when integrating with external systems that provide their own public keys.

  2. Encryption profile fallback — If publicKey is omitted, the endpoint uses the RSA public key from your TokenEx encryption profile, configured in the Browser Based Encryption section of the client portal.

Error Codes

Error CodeDescription
8610JWE encryption failed
8611Invalid or missing JWE options header (missing header, invalid Base64, or invalid JSON)
8612Invalid or missing JWE algorithm (alg field)
8613Invalid or missing JWE encryption method (enc field)
8614Invalid or missing JWE public key

Permissions

This endpoint requires the Detokenize permission. Ensure your API key has this permission enabled in the TokenEx client portal.