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

Set the JWS Payload from a StringBuilder

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.SetPayloadSb, which sets the payload to be signed from a StringBuilder.

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,
  Chilkat.StringBuilder;

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

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

begin
  success := False;

  jws := TJws.Create;

  //  Set the payload from a StringBuilder.
  sbPayload := TStringBuilder.Create;
  sbPayload.Append('This is the content to sign.');

  bIncludeBom := False;
  success := jws.SetPayloadSb(sbPayload,'utf-8',bIncludeBom);
  if (success = False) then
    begin
      WriteLn(jws.LastErrorText);
      Exit;
    end;
  WriteLn('Payload set.');


  jws.Free;
  sbPayload.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.