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

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Jwe;

public class ChilkatExample {

    public static void main(String[] args) {
        Jwe jwe = new Jwe();

        // Load the JWE.
        String jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>";
        try {
            jwe.loadJwe(jweCompact);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            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.
        JsonObject json = new JsonObject();
        try {
            jwe.getProtectedHeader(json);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

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