Sample code for 30+ languages & platforms
Tcl

Get a JWS Unprotected Header

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetUnprotectedH, which copies the optional unprotected header of a signature into a JsonObject.

Background. The unprotected header is present only in JSON serialization forms that carry one. It is not covered by the signature.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set jws [new_CkJws]

#  Load the JWS compact serialization.
set jwsCompact "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
set success [CkJws_LoadJws $jws $jwsCompact]
if {$success == 0} then {
    puts [CkJws_lastErrorText $jws]
    delete_CkJws $jws
    exit
}

#  Copy the optional unprotected header of signature 0 into a JsonObject.  This applies to JWS in a
#  JSON serialization form that carries an unprotected header.
set json [new_CkJsonObject]

set success [CkJws_GetUnprotectedH $jws 0 $json]
if {$success == 0} then {
    puts [CkJws_lastErrorText $jws]
    delete_CkJws $jws
    delete_CkJsonObject $json
    exit
}

CkJsonObject_put_EmitCompact $json 0
puts [CkJsonObject_emit $json]

delete_CkJws $jws
delete_CkJsonObject $json