Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

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 Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.Jwe,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  jwe: TJwe;
  jweCompact: string;
  json: TJsonObject;

begin
  success := False;

  jwe := TJwe.Create;

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

  //  Copy the entire loaded JWE structure into a JsonObject.  This is the full JWE representation, not a
  //  decoded or merged JOSE header.
  json := TJsonObject.Create;
  success := jwe.GetHeader(json);
  if (success = False) then
    begin
      WriteLn(jwe.LastErrorText);
      Exit;
    end;

  json.EmitCompact := False;
  WriteLn(json.Emit());


  jwe.Free;
  json.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.