Sample code for 30+ languages & platforms
Xbase++

Get the JWE Protected Header

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.GetProtectedHeader, which copies the decoded shared JWE protected header into a JsonObject.

Background. Only the protected header is returned; it is not merged with the shared unprotected header or any per-recipient header.

Chilkat Xbase++ Downloads

Xbase++
LOCAL nSuccess
LOCAL oJwe
LOCAL cJweCompact
LOCAL oJson

nSuccess := 0

oJwe := CreateObject("Chilkat.Jwe")

//  Load the JWE.
cJweCompact := "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>"
nSuccess := oJwe:LoadJwe(cJweCompact)
IF (nSuccess == 0)
    ? oJwe:LastErrorText
    oJwe:destroy()
    RETURN
ENDIF

//  Copy the decoded shared JWE protected header into a JsonObject.  Only the protected header is
//  returned; it is not merged with the unprotected or per-recipient headers.
oJson := CreateObject("Chilkat.JsonObject")
nSuccess := oJwe:GetProtectedHeader(oJson)
IF (nSuccess == 0)
    ? oJwe:LastErrorText
    oJwe:destroy()
    oJson:destroy()
    RETURN
ENDIF

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

oJwe:destroy()
oJson:destroy()