Sample code for 30+ languages & platforms
Java

Get the Entire Loaded JWE Structure

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.GetHeader, which copies the entire currently loaded JWE structure into a JsonObject.

Background. This is the full JWE representation, not a decoded or merged JOSE header. It can contain the protected, unprotected, and per-recipient header material.

Chilkat Java Downloads

Java
import com.chilkatsoft.*;

public class ChilkatExample {

  static {
    try {
        System.loadLibrary("chilkat");
    } catch (UnsatisfiedLinkError e) {
      System.err.println("Native code library failed to load.\n" + e);
      System.exit(1);
    }
  }

  public static void main(String argv[])
  {
    boolean success = false;

    CkJwe jwe = new CkJwe();

    //  Load the JWE.
    String jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>";
    success = jwe.LoadJwe(jweCompact);
    if (success == false) {
        System.out.println(jwe.lastErrorText());
        return;
        }

    //  Copy the entire loaded JWE structure into a JsonObject.  This is the full JWE representation, not a
    //  decoded or merged JOSE header.
    CkJsonObject json = new CkJsonObject();
    success = jwe.GetHeader(json);
    if (success == false) {
        System.out.println(jwe.lastErrorText());
        return;
        }

    json.put_EmitCompact(false);
    System.out.println(json.emit());
  }
}