Sample code for 30+ languages & platforms
Delphi ActiveX

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 Delphi ActiveX Downloads

Delphi ActiveX
var
success: Integer;
jwe: TChilkatJwe;
jweCompact: WideString;
json: TChilkatJsonObject;

begin
success := 0;

jwe := TChilkatJwe.Create(Self);

//  Load the JWE.
jweCompact := 'eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>';
success := jwe.LoadJwe(jweCompact);
if (success = 0) then
  begin
    Memo1.Lines.Add(jwe.LastErrorText);
    Exit;
  end;

//  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.
json := TChilkatJsonObject.Create(Self);
success := jwe.GetProtectedHeader(json.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(jwe.LastErrorText);
    Exit;
  end;

json.EmitCompact := 0;
Memo1.Lines.Add(json.Emit());