Generate a JWE (JSON Web Encryption) Data Object (2024)

The JWE is built using the elements:

  1. header:

    Includes the kid and alg parameters.
  2. Content Encryption Key (CEK):

    The unique encryption key used to encrypt the token
  3. ciphertext

    The encrypted JSON payload
  4. initialization vector:

    A base64 encoded randomly generated number that is used along with a secret key to encrypt data.
  5. authentication tag:

    Created during the encryption, this tag allows the verifier to prove the integrity of the ciphertext and the header

The payload should use this format:

header.cek.cyphertext.initialization_vector.auth_tag

For more information about JWE Data Objects, see RFC 7516

Example Payload

IMPORTANT

Line breaks have been added for readability and formatting.

eyJraWQiOiIwMFN2SWFHSWZ5YXc4OTdyRGVHOWVGZE9ES2FDS2MxcSIsImVuYyI6IkEyNTZHQ00iLCJhbGciOiJSU0EtT0FFUCJ9.juQDhF5XcZ1rDbupn1nZ1qHhephzWpa8FumH4KrsD0yF1tCOD0L8WfpSyd5VGIewb4I1IipmSB5vV0O3Cb6FrNLipjFq-oexFRwSK92NbB88ySFO-7FyvPddiqaQFkA81xn8nwdoHMwUsQuqe8Ts_krLsvYghmscxXKkwcEKqxoWbmD-yEfvKxGyHACLprAKLm-xusexaJLF42OTxYuEhzzrSe6MRll0zXuk2DAhtUL2oHCgu8P3shgJBJqsOPcAFtwtLBRoDwlDt0ybOHjd34Svbpgf_3ncFnDkEQYe5QeElEHaB2a0Nbwo61I1UETfhedHQc8IMtDmVuKk9pgCTg.uWrwGp2jZxZd5wF0.oFzZ3I2ry77jf-3wB_2q8G-0tbYJWQj88NdzRmVNO34JbreX5WOCju7ntvN8h83NJXEA_cQech2PEGIZV_tADBaLbSxJeitYKwaQhs_tRVrzrcd8Qhgs4OADfky2m310eV8bUG8D4GZBKRHL6ScLf5p30b6Hoa5fDYsU7IHNyCReiaiGPExlY4luwL9QQxrfY2LTv74Pcqyh-B4byNxR5hTw3SJm7DT7YQLl6_-2ROqJhJoweTdDJtmJoM-LxKEij2TLgHBdqso9f036dfn0SHLl1vG86C1-6DA9yFIZB3gLYnyom1jZuGxUOPXDojUfXo0O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QBuSC3acFu28x3NL8cmR5iqy7sBGUKcwt_ogX9ZoQyFzUTFOw.QqKIuF8EnuhOTM8PvGEs8A

Sample Java Code

This Java example includes the code that can be used to generate the JWE Data Object:

package com.cybersource.example.service;import com.auth0.jwt.JWT;import com.auth0.jwt.JWTVerifier;import com.auth0.jwt.algorithms.Algorithm;import com.cybersource.example.config.ApplicationProperties;import com.cybersource.example.domain.CaptureContextResponseBody;import com.cybersource.example.domain.CaptureContextResponseHeader;import com.cybersource.example.domain.JWK;import com.fasterxml.jackson.databind.ObjectMapper;import lombok.RequiredArgsConstructor;import lombok.SneakyThrows;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Service;import org.springframework.web.client.RestTemplate;import java.math.BigInteger;import java.security.KeyFactory;import java.security.interfaces.RSAPublicKey;import java.security.spec.RSAPublicKeySpec;import java.util.Base64;import java.util.Base64.Decoder;@Service@RequiredArgsConstructorpublic class JwtProcessorService { @Autowired private final ApplicationProperties applicationProperties; @SneakyThrows public String verifyJwtAndGetDecodedBody(final String jwt) { // Parse the JWT response into header, payload, and signature final String[] jwtChunks = jwt.split("\\."); final Decoder decoder = Base64.getUrlDecoder(); final String header = new String(decoder.decode(jwtChunks[0])); final String body = new String(decoder.decode(jwtChunks[1])); // Normally you'd want to cache the header and JWK, and only hit /flex/v2/public-keys/{kid} when the key rotates. // For simplicity and demonstration's sake let's retrieve it every time final JWK publicKeyJWK = getPublicKeyFromHeader(header); // Construct an RSA Key out of the response we got from the /public-keys endpoint final BigInteger modulus = new BigInteger(1, decoder.decode(publicKeyJWK.n())); final BigInteger exponent = new BigInteger(1, decoder.decode(publicKeyJWK.e())); final RSAPublicKey rsaPublicKey = (RSAPublicKey) KeyFactory.getInstance("RSA").generatePublic(new RSAPublicKeySpec(modulus, exponent)); // Verify the JWT's signature using the public key final Algorithm algorithm = Algorithm.RSA256(rsaPublicKey, null); final JWTVerifier verifier = JWT.require(algorithm).build(); // This will throw a runtime exception if there's a signature mismatch. verifier.verify(jwt); return body; } @SneakyThrows public String getClientVersionFromDecodedBody(final String jwtBody) { // Map the JWT Body to a POJO final CaptureContextResponseBody mappedBody = new ObjectMapper().readValue(jwtBody, CaptureContextResponseBody.class); // Dynamically retrieve the client library return mappedBody.ctx().stream().findFirst() .map(wrapper -> wrapper.data().clientLibrary()) .orElseThrow(); } @SneakyThrows private JWK getPublicKeyFromHeader(final String jwtHeader) { // Again, this process should be cached so you don't need to hit /public-keys // You'd want to look for a difference in the header's value (e.g. new key id [kid]) to refresh your cache final CaptureContextResponseHeader mappedJwtHeader = new ObjectMapper().readValue(jwtHeader, CaptureContextResponseHeader.class); final RestTemplate restTemplate = new RestTemplate(); final ResponseEntity<String> response = restTemplate.getForEntity( "https://" + applicationProperties.getRequestHost() + "/flex/v2/public-keys/" + mappedJwtHeader.kid(), String.class); return new ObjectMapper().readValue(response.getBody(), JWK.class); }}

Generate a JWE (JSON Web Encryption) Data Object (2024)
Top Articles
Simple Moving Average: SMA in Trading
Stellar Lumens (XLM) Wallet | Set Up Your Stellar Lumens (XLM) Wallet | Uphold
Brady Hughes Justified
Restored Republic January 20 2023
Craftsman M230 Lawn Mower Oil Change
Vaya Timeclock
30% OFF Jellycat Promo Code - September 2024 (*NEW*)
Top Golf 3000 Clubs
The Blind Showtimes Near Showcase Cinemas Springdale
Valentina Gonzalez Leaked Videos And Images - EroThots
FIX: Spacebar, Enter, or Backspace Not Working
Www.paystubportal.com/7-11 Login
Cool Math Games Bucketball
Https //Advanceautoparts.4Myrebate.com
Bc Hyundai Tupelo Ms
How to find cash from balance sheet?
Spider-Man: Across The Spider-Verse Showtimes Near Marcus Bay Park Cinema
How To Cancel Goodnotes Subscription
Booknet.com Contract Marriage 2
Craigslist Missoula Atv
Bing Chilling Words Romanized
Hdmovie 2
Winco Employee Handbook 2022
R. Kelly Net Worth 2024: The King Of R&B's Rise And Fall
Silky Jet Water Flosser
What Individuals Need to Know When Raising Money for a Charitable Cause
Combies Overlijden no. 02, Stempels: 2 teksten + 1 tag/label & Stansen: 3 tags/labels.
Downtown Dispensary Promo Code
Penn State Service Management
Will there be a The Tower season 4? Latest news and speculation
897 W Valley Blvd
Puffin Asmr Leak
100 Million Naira In Dollars
Green Bay Crime Reports Police Fire And Rescue
404-459-1280
Audi Q3 | 2023 - 2024 | De Waal Autogroep
Texas Baseball Officially Releases 2023 Schedule
67-72 Chevy Truck Parts Craigslist
Hannibal Mo Craigslist Pets
Craigslist Pets Huntsville Alabama
Tiny Pains When Giving Blood Nyt Crossword
Noaa Duluth Mn
Arigreyfr
Craigslist Antique
Garland County Mugshots Today
Unblocked Games - Gun Mayhem
Cult Collectibles - True Crime, Cults, and Murderabilia
Mega Millions Lottery - Winning Numbers & Results
Mcoc Black Panther
Naomi Soraya Zelda
Cvs Minute Clinic Women's Services
Chitterlings (Chitlins)
Latest Posts
Article information

Author: Ray Christiansen

Last Updated:

Views: 6441

Rating: 4.9 / 5 (69 voted)

Reviews: 84% of readers found this page helpful

Author information

Name: Ray Christiansen

Birthday: 1998-05-04

Address: Apt. 814 34339 Sauer Islands, Hirtheville, GA 02446-8771

Phone: +337636892828

Job: Lead Hospitality Designer

Hobby: Urban exploration, Tai chi, Lockpicking, Fashion, Gunsmithing, Pottery, Geocaching

Introduction: My name is Ray Christiansen, I am a fair, good, cute, gentle, vast, glamorous, excited person who loves writing and wants to share my knowledge and understanding with you.