Sample code for 30+ languages & platforms
Unicode C

Get the JWS Payload into a StringBuilder

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetPayloadSb, which writes the payload of a loaded JWS as text into a StringBuilder, decoded using the given charset.

Background. In practice, validate the signature before trusting the payload.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkJwsW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkJwsW jws;
    const wchar_t *jwsCompact;
    HCkStringBuilderW sbPayload;

    success = FALSE;

    jws = CkJwsW_Create();

    //  Load the JWS compact serialization.
    jwsCompact = L"eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>";
    success = CkJwsW_LoadJws(jws,jwsCompact);
    if (success == FALSE) {
        wprintf(L"%s\n",CkJwsW_lastErrorText(jws));
        CkJwsW_Dispose(jws);
        return;
    }

    //  Get the JWS payload as text into a StringBuilder, decoded using the given charset.
    sbPayload = CkStringBuilderW_Create();
    success = CkJwsW_GetPayloadSb(jws,L"utf-8",sbPayload);
    if (success == FALSE) {
        wprintf(L"%s\n",CkJwsW_lastErrorText(jws));
        CkJwsW_Dispose(jws);
        CkStringBuilderW_Dispose(sbPayload);
        return;
    }

    wprintf(L"%s\n",CkStringBuilderW_getAsString(sbPayload));


    CkJwsW_Dispose(jws);
    CkStringBuilderW_Dispose(sbPayload);

    }