Sample code for 30+ languages & platforms
Delphi ActiveX

Set the JWE Protected Header

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.SetProtectedHeader, which sets the integrity-protected JWE header from a JsonObject. The header specifies the key-management algorithm (alg) and content-encryption algorithm (enc).

Background. The protected header is integrity-protected and applies to all recipients. It is configured before encrypting.

Chilkat Delphi ActiveX Downloads

Delphi ActiveX
var
success: Integer;
jwe: TChilkatJwe;
header: TChilkatJsonObject;

begin
success := 0;

jwe := TChilkatJwe.Create(Self);

//  Build the JWE protected header.  The "alg" member names the key-management algorithm and the "enc"
//  member names the content-encryption algorithm.
header := TChilkatJsonObject.Create(Self);
header.UpdateString('alg','A256KW');
header.UpdateString('enc','A256GCM');

//  Set the protected header on the JWE.  The protected header is integrity-protected and applies to
//  all recipients.
success := jwe.SetProtectedHeader(header.ControlInterface);
if (success = 0) then
  begin
    Memo1.Lines.Add(jwe.LastErrorText);
    Exit;
  end;
Memo1.Lines.Add('Protected header set.');