Sample code for 30+ languages & platforms
Xbase++

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 Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oJws
LOCAL cJwsCompact
LOCAL oJson

nSuccess := 0

oJws := CreateObject("Chilkat.Jws")

//  Load the JWS compact serialization.
cJwsCompact := "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
nSuccess := oJws:LoadJws(cJwsCompact)
IF (nSuccess == 0)
    ? oJws:LastErrorText
    oJws:destroy()
    RETURN
ENDIF

//  Copy the decoded protected header of signature 0 into a JsonObject.
oJson := CreateObject("Chilkat.JsonObject")
nSuccess := oJws:GetProtectedH(0, oJson)
IF (nSuccess == 0)
    ? oJws:LastErrorText
    oJws:destroy()
    oJson:destroy()
    RETURN
ENDIF

oJson:EmitCompact := 0
? oJson:Emit()

oJws:destroy()
oJson:destroy()