Sample code for 30+ languages & platforms
Delphi ActiveX

Get a JWS Protected Header

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetProtectedH, which copies the decoded protected header of a signature into a JsonObject.

Background. The protected header is integrity-protected by the signature. Inspecting it (for example the alg value) is useful before deciding how to validate.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
var
success: Integer;
jws: TChilkatJws;
jwsCompact: WideString;
json: TChilkatJsonObject;

begin
success := 0;

jws := TChilkatJws.Create(Self);

//  Load the JWS compact serialization.
jwsCompact := 'eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>';
success := jws.LoadJws(jwsCompact);
if (success = 0) then
  begin
    Memo1.Lines.Add(jws.LastErrorText);
    Exit;
  end;

//  Copy the decoded protected header of signature 0 into a JsonObject.
json := TChilkatJsonObject.Create(Self);
success := jws.GetProtectedH(0,json.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(jws.LastErrorText);
    Exit;
  end;

json.EmitCompact := 0;
Memo1.Lines.Add(json.Emit());