Sample code for 30+ languages & platforms
Delphi DLL

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 DLL Downloads

Delphi DLL
var
success: Boolean;
jws: HCkJws;
header: HCkJsonObject;

begin
success := False;

jws := CkJws_Create();

//  Build the JWS protected header.  The "alg" member names the signature algorithm.
header := CkJsonObject_Create();
CkJsonObject_UpdateString(header,'alg','HS256');

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

CkJws_Dispose(jws);
CkJsonObject_Dispose(header);