Sample code for 30+ languages & platforms
JavaScript

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.
Note
This example is intended for running within a Chilkat.Js embedded JavaScript engine. All Chilkat JavaScript examples require Chilkat v11.4.0 or greater.
JavaScript
var success = false;

var jwe = new CkJwe();

//  Load the JWE.
var jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>";
success = jwe.LoadJwe(jweCompact);
if (success == false) {
    console.log(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.
var json = new CkJsonObject();
success = jwe.GetProtectedHeader(json);
if (success == false) {
    console.log(jwe.LastErrorText);
    return;
}

json.EmitCompact = false;
console.log(json.Emit());