Sample code for 30+ languages & platforms
C

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 C Downloads

C
#include <C_CkJws.h>
#include <C_CkBinData.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkJws jws;
    const char *jwsCompact;
    HCkBinData bdPayload;

    success = FALSE;

    jws = CkJws_Create();

    //  Load the JWS compact serialization.
    jwsCompact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>";
    success = CkJws_LoadJws(jws,jwsCompact);
    if (success == FALSE) {
        printf("%s\n",CkJws_lastErrorText(jws));
        CkJws_Dispose(jws);
        return;
    }

    //  Get the JWS payload as raw bytes into a BinData.
    bdPayload = CkBinData_Create();
    success = CkJws_GetPayloadBd(jws,bdPayload);
    if (success == FALSE) {
        printf("%s\n",CkJws_lastErrorText(jws));
        CkJws_Dispose(jws);
        CkBinData_Dispose(bdPayload);
        return;
    }

    printf("Payload is %d bytes.\n",CkBinData_getNumBytes(bdPayload));


    CkJws_Dispose(jws);
    CkBinData_Dispose(bdPayload);

    }