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

Set the JWS Payload

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.SetPayload, which sets the content to be signed. The charset converts the text to bytes, and a flag controls whether a byte-order mark is included.

Background. JWS (JSON Web Signature) integrity-protects a payload with a signature or MAC. The header alg names the algorithm; this example uses HMAC-SHA256 (HS256) with a symmetric MAC key.

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.Jws;

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

procedure RunDemo;
var
  success: Boolean;
  jws: TJws;
  bIncludeBom: Boolean;

begin
  success := False;

  jws := TJws.Create;

  //  Set the payload (the content to be signed).  The 2nd argument is the charset used to convert the
  //  text to bytes, and the 3rd controls whether a byte-order mark is included.
  bIncludeBom := False;
  success := jws.SetPayload('This is the content to sign.','utf-8',bIncludeBom);
  if (success = False) then
    begin
      WriteLn(jws.LastErrorText);
      Exit;
    end;
  WriteLn('Payload set.');


  jws.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.