Sample code for 30+ languages & platforms
Tcl

Get a JWS Protected Header

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetProtectedH, which copies the decoded protected header of a signature into a JsonObject.

Background. The protected header is integrity-protected by the signature. Inspecting it (for example the alg value) is useful before deciding how to validate.

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 decoded protected header of signature 0 into a JsonObject.
set json [new_CkJsonObject]

set success [CkJws_GetProtectedH $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