Sample code for 30+ languages & platforms
PureBasic

Get the Entire Loaded JWE Structure

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.GetHeader, which copies the entire currently loaded JWE structure into a JsonObject.

Background. This is the full JWE representation, not a decoded or merged JOSE header. It can contain the protected, unprotected, and per-recipient header material.

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkJwe.pb"
IncludeFile "CkJsonObject.pb"

Procedure ChilkatExample()

    success.i = 0

    jwe.i = CkJwe::ckCreate()
    If jwe.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    ;  Load the JWE.
    jweCompact.s = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>"
    success = CkJwe::ckLoadJwe(jwe,jweCompact)
    If success = 0
        Debug CkJwe::ckLastErrorText(jwe)
        CkJwe::ckDispose(jwe)
        ProcedureReturn
    EndIf

    ;  Copy the entire loaded JWE structure into a JsonObject.  This is the full JWE representation, not a
    ;  decoded or merged JOSE header.
    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkJwe::ckGetHeader(jwe,json)
    If success = 0
        Debug CkJwe::ckLastErrorText(jwe)
        CkJwe::ckDispose(jwe)
        CkJsonObject::ckDispose(json)
        ProcedureReturn
    EndIf

    CkJsonObject::setCkEmitCompact(json, 0)
    Debug CkJsonObject::ckEmit(json)


    CkJwe::ckDispose(jwe)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure