Sample code for 30+ languages & platforms
Java

Get the JWE Protected Header

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.GetProtectedHeader, which copies the decoded shared JWE protected header into a JsonObject.

Background. Only the protected header is returned; it is not merged with the shared unprotected header or any per-recipient header.

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 decoded shared JWE protected header into a JsonObject.  Only the protected header is
    //  returned; it is not merged with the unprotected or per-recipient headers.
    CkJsonObject json = new CkJsonObject();
    success = jwe.GetProtectedHeader(json);
    if (success == false) {
        System.out.println(jwe.lastErrorText());
        return;
        }

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