JweToken Class

Represents a parsed JWE (JSON Web Encryption) token in the compact serialization form defined by RFC 7516. A JweToken holds the components needed for decryption: protected header, ephemeral public key, wrapped content encryption key, initialization vector, ciphertext, authentication tag, and Additional Authenticated Data (AAD).

System

Use JweToken when you need programmatic access to the individual components of a JWE compact serialization token. For example, to inspect the algorithm used, verify the ephemeral public key, or route decryption based on the enc header. The typical flow is: parseJwe → inspect the header via getAlgorithm() / getEncryptionAlgorithm() → call Crypto.decrypt(...) with the extracted components.

Crypto.parseJwe(Blob) produces an instance. The caller then passes the extracted components to the nine-argument Crypto.decrypt(...) overload to complete the two-step JWE decryption flow. JweToken is immutable. All fields are set at construction and exposed only through read-only accessors.

The following are constructors for JweToken.

Creates a new JweToken from the parsed components of a JWE compact serialization token. This constructor is typically invoked internally after Crypto.parseJwe(Blob) has decomposed the token.

public JweToken(String alg, String enc, Blob epk, Blob encrypted_key, Blob iv, Blob ciphertext, Blob tag, Blob aad)

  • alg: Type: StringKey management algorithm from the JWE protected header (alg field). For example, ECDH-ES+A128KW.
  • enc: Type: String Content encryption algorithm from the JWE protected header (enc field). For example, A128GCM or A256CBC-HS512.
  • epk: Type: Blob Ephemeral public key from the JWE protected header (epk JWK), encoded as X.509 SubjectPublicKeyInfo DER bytes.
  • encrypted_key: Type: Blob Encrypted content encryption key (wrapped CEK) — part 2 of the compact serialization.
  • iv: Type: Blob Initialization vector for content decryption — part 3 of the compact serialization.
  • ciphertext: Type: Blob Encrypted content — part 4 of the compact serialization.
  • tag: Type: Blob Authentication tag — part 5 of the compact serialization.
  • aad: Type: Blob Additional Authenticated Data — the ASCII bytes of the base64url-encoded protected header (per RFC 7516 §5.1, step 14).

The following are methods for JweToken.

  • getAad()

    Returns the Additional Authenticated Data (AAD) associated with the JWE token. Per RFC 7516 §5.1 step 14, the AAD is the US-ASCII byte encoding of the base64url-encoded JWE protected header. This value is bound to the ciphertext by the AEAD algorithm and must match at decryption time.

  • getAlgorithm()

    Returns the key management algorithm from the JWE protected header. This is the alg value that governs how the content encryption key (CEK) is protected.

  • getCiphertext()

    Returns the encrypted content of the JWE — the fourth component of the compact serialization (before the authentication tag).

  • getEncryptedKey()

    Returns the wrapped content encryption key (CEK), the second component of the JWE compact serialization. This value is decrypted using the recipient’s key management key (per getAlgorithm()) to recover the CEK, which is then used to decrypt getCiphertext().

  • getEncryptionAlgorithm()

    Returns the content encryption algorithm from the JWE protected header. This is the enc value that governs how the payload is encrypted.

  • getEphemeralPublicKey()

    Returns the ephemeral public key from the JWE protected header (the epk JWK). The key is returned in X.509 SubjectPublicKeyInfo DER encoding, suitable for passing to standard key deserialization utilities.

  • getIv()

    Returns the initialization vector used for content decryption — the third component of the JWE compact serialization.

  • getTag()

    Returns the authentication tag — the fifth and final component of the JWE compact serialization. The tag is used by the AEAD algorithm to detect tampering with the ciphertext or AAD.

  • toString()

    Returns a string representation of the token suitable for debugging and logging. The output contains only metadata (algorithm identifiers and byte lengths) and never exposes the ephemeral public key, wrapped CEK, ciphertext, or authentication tag.

Returns the Additional Authenticated Data (AAD) associated with the JWE token. Per RFC 7516 §5.1 step 14, the AAD is the US-ASCII byte encoding of the base64url-encoded JWE protected header. This value is bound to the ciphertext by the AEAD algorithm and must match at decryption time.

public Blob getAad()

Type: Blob

The Additional Authenticated Data bytes. Never null for tokens produced by Crypto.parseJwe.

Returns the key management algorithm from the JWE protected header. This is the alg value that governs how the content encryption key (CEK) is protected.

public String getAlgorithm()

Type: String

The key management algorithm identifier. The supported values are ECDH-ES+A128KW, ECDH-ES+A192KW, and ECDH-ES+A256KW.

Returns the encrypted content of the JWE — the fourth component of the compact serialization (before the authentication tag).

public Blob getCiphertext()

Type: Blob

The ciphertext bytes. Length depends on the content encryption algorithm and the size of the original plaintext. The maximum supported ciphertext size is approximately 1 MB plus padding and tag overhead.

Returns the wrapped content encryption key (CEK), the second component of the JWE compact serialization. This value is decrypted using the recipient’s key management key (per getAlgorithm()) to recover the CEK, which is then used to decrypt getCiphertext().

public Blob getEncryptedKey()

Type: Blob

The encrypted content encryption key bytes. Always present for the supported ECDH-ES+A*KW algorithms because these wrap the CEK with AES Key Wrap.

Returns the content encryption algorithm from the JWE protected header. This is the enc value that governs how the payload is encrypted.

public String getEncryptionAlgorithm()

Type: String

The content encryption algorithm identifier. Supported values include:

valuedescription
A128GCMAES-128 in Galois/Counter Mode
A192GCMAES-192 in Galois/Counter Mode
A256GCMAES-256 in Galois/Counter Mode
A128CBC-HS256AES-128 in CBC mode with HMAC-SHA-256
A192CBC-HS384AES-192 in CBC mode with HMAC-SHA-384
A256CBC-HS512AES-256 in CBC mode with HMAC-SHA-512

An unsupported value causes Crypto.parseJwe to throw a SecurityException. Therefore, this method never returns an unsupported value for a token that has been parsed successfully.

Returns the ephemeral public key from the JWE protected header (the epk JWK). The key is returned in X.509 SubjectPublicKeyInfo DER encoding, suitable for passing to standard key deserialization utilities.

public Blob getEphemeralPublicKey()

Type: Blob

The DER-encoded ephemeral public key bytes. Usage For ECDH-ES key agreement algorithms, the ephemeral public key contributes half of the shared secret. Applications that need to perform key agreement outside of Crypto.decrypt(...) can use this method to obtain the peer’s ephemeral key material.

Returns the initialization vector used for content decryption — the third component of the JWE compact serialization.

public Blob getIv()

Type: Blob

The initialization vector bytes. Length depends on the content encryption algorithm:

  • 12 bytes for A128GCM / A192GCM / A256GCM
  • 16 bytes for A128CBC-HS256 / A192CBC-HS384 / A256CBC-HS512

Returns the authentication tag — the fifth and final component of the JWE compact serialization. The tag is used by the AEAD algorithm to detect tampering with the ciphertext or AAD.

public Blob getTag()

Type: Blob

The authentication tag bytes. Length depends on the content encryption algorithm:

  • 16 bytes for GCM variants (A128GCM, A192GCM, and A256GCM)
  • 16, 24, or 32 bytes for CBC-HS variants (A128CBC-HS256, A192CBC-HS384, and A256CBC-HS512 respectively)

Returns a string representation of the token suitable for debugging and logging. The output contains only metadata (algorithm identifiers and byte lengths) and never exposes the ephemeral public key, wrapped CEK, ciphertext, or authentication tag.

public String toString()

Type: String

A formatted string of the form: