Lazarus Pascal
Lazarus Pascal
Set the JWS Payload from BinData
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.SetPayloadBd, which sets the payload to be signed from the binary bytes in a BinData.
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 Lazarus Pascal Downloads
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.BinData,
Chilkat.Jws;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
jws: TJws;
bdPayload: TBinData;
begin
success := False;
jws := TJws.Create;
// Set the payload from the binary bytes in a BinData.
bdPayload := TBinData.Create;
bdPayload.AppendString('Binary content to sign.','utf-8');
success := jws.SetPayloadBd(bdPayload);
if (success = False) then
begin
WriteLn(jws.LastErrorText);
Exit;
end;
WriteLn('Payload set.');
jws.Free;
bdPayload.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.