Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Jwe
oleobject loo_Header

li_Success = 0

loo_Jwe = create oleobject
li_rc = loo_Jwe.ConnectToNewObject("Chilkat.Jwe")
if li_rc < 0 then
    destroy loo_Jwe
    MessageBox("Error","Connecting to COM object failed")
    return
end if

//  Build the JWE protected header.  The "alg" member names the key-management algorithm and the "enc"
//  member names the content-encryption algorithm.
loo_Header = create oleobject
li_rc = loo_Header.ConnectToNewObject("Chilkat.JsonObject")

loo_Header.UpdateString("alg","A256KW")
loo_Header.UpdateString("enc","A256GCM")

//  Set the protected header on the JWE.  The protected header is integrity-protected and applies to
//  all recipients.
li_Success = loo_Jwe.SetProtectedHeader(loo_Header)
if li_Success = 0 then
    Write-Debug loo_Jwe.LastErrorText
    destroy loo_Jwe
    destroy loo_Header
    return
end if

Write-Debug "Protected header set."


destroy loo_Jwe
destroy loo_Header