Sample code for 30+ languages & platforms
C

Get the JWS Payload as a String

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetPayload, which returns the payload of a loaded JWS as text, decoded using the given charset.

Background. In practice, validate the signature before trusting the payload. Getting the payload retrieves the signed content.

Chilkat C Downloads

C
#include <C_CkJws.h>

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

    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;
    }

    //  Return the JWS payload as text, decoded using the given charset.
    payload = CkJws_getPayload(jws,"utf-8");
    if (CkJws_getLastMethodSuccess(jws) == FALSE) {
        printf("%s\n",CkJws_lastErrorText(jws));
        CkJws_Dispose(jws);
        return;
    }

    printf("%s\n",payload);


    CkJws_Dispose(jws);

    }