Sample code for 30+ languages & platforms
Delphi ActiveX

Set the JWS Protected Header

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.SetProtectedHeader, which sets the integrity-protected header for a signer from a JsonObject. The header specifies the signature algorithm (alg).

Background. The protected header is covered by the signature, so it cannot be altered without invalidating the JWS. It is configured before creating the JWS.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
var
success: Integer;
jws: TChilkatJws;
header: TChilkatJsonObject;

begin
success := 0;

jws := TChilkatJws.Create(Self);

//  Build the JWS protected header.  The "alg" member names the signature algorithm.
header := TChilkatJsonObject.Create(Self);
header.UpdateString('alg','HS256');

//  Set the protected header for signer index 0.  The protected header is integrity-protected: it is
//  covered by the signature.
success := jws.SetProtectedHeader(0,header.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(jws.LastErrorText);
    Exit;
  end;
Memo1.Lines.Add('Protected header set.');