Sample code for 30+ languages & platforms
Tcl

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

Tcl

load ./chilkat.dll

set success 0

set jws [new_CkJws]

#  Build the JWS protected header.  The "alg" member names the signature algorithm.
set header [new_CkJsonObject]

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.
set success [CkJws_SetProtectedHeader $jws 0 $header]
if {$success == 0} then {
    puts [CkJws_lastErrorText $jws]
    delete_CkJws $jws
    delete_CkJsonObject $header
    exit
}

puts "Protected header set."

delete_CkJws $jws
delete_CkJsonObject $header