Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Jws
oleobject loo_Header

li_Success = 0

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

//  Build the JWS protected header.  The "alg" member names the signature algorithm.
loo_Header = create oleobject
li_rc = loo_Header.ConnectToNewObject("Chilkat.JsonObject")

loo_Header.UpdateString("alg","HS256")

//  Set the protected header for signer index 0.  The protected header is integrity-protected: it is
//  covered by the signature.
li_Success = loo_Jws.SetProtectedHeader(0,loo_Header)
if li_Success = 0 then
    Write-Debug loo_Jws.LastErrorText
    destroy loo_Jws
    destroy loo_Header
    return
end if

Write-Debug "Protected header set."


destroy loo_Jws
destroy loo_Header