Sample code for 30+ languages & platforms
DataFlex

Get the JWS Payload into BinData

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetPayloadBd, which writes the payload of a loaded JWS as raw bytes into a BinData.

Background. This is used when the payload is binary. In practice, validate the signature before trusting the payload.

Chilkat DataFlex Downloads

DataFlex
Use ChilkatAx-win32.pkg

Procedure Test
    Boolean iSuccess
    Handle hoJws
    String sJwsCompact
    Variant vBdPayload
    Handle hoBdPayload
    String sTemp1
    Integer iTemp1

    Move False To iSuccess

    Get Create (RefClass(cComChilkatJws)) To hoJws
    If (Not(IsComObjectCreated(hoJws))) Begin
        Send CreateComObject of hoJws
    End

    //  Load the JWS compact serialization.
    Move "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>" To sJwsCompact
    Get ComLoadJws Of hoJws sJwsCompact To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoJws To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    //  Get the JWS payload as raw bytes into a BinData.
    Get Create (RefClass(cComChilkatBinData)) To hoBdPayload
    If (Not(IsComObjectCreated(hoBdPayload))) Begin
        Send CreateComObject of hoBdPayload
    End
    Get pvComObject of hoBdPayload to vBdPayload
    Get ComGetPayloadBd Of hoJws vBdPayload To iSuccess
    If (iSuccess = False) Begin
        Get ComLastErrorText Of hoJws To sTemp1
        Showln sTemp1
        Procedure_Return
    End

    Get ComNumBytes Of hoBdPayload To iTemp1
    Showln "Payload is " iTemp1 " bytes."


End_Procedure