Sample code for 30+ languages & platforms
Unicode C

Get a JWS Unprotected Header

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.GetUnprotectedH, which copies the optional unprotected header of a signature into a JsonObject.

Background. The unprotected header is present only in JSON serialization forms that carry one. It is not covered by the signature.

Chilkat Unicode C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkJwsW jws;
    const wchar_t *jwsCompact;
    HCkJsonObjectW json;

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

    //  Copy the optional unprotected header of signature 0 into a JsonObject.  This applies to JWS in a
    //  JSON serialization form that carries an unprotected header.
    json = CkJsonObjectW_Create();
    success = CkJwsW_GetUnprotectedH(jws,0,json);
    if (success == FALSE) {
        wprintf(L"%s\n",CkJwsW_lastErrorText(jws));
        CkJwsW_Dispose(jws);
        CkJsonObjectW_Dispose(json);
        return;
    }

    CkJsonObjectW_putEmitCompact(json,FALSE);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));


    CkJwsW_Dispose(jws);
    CkJsonObjectW_Dispose(json);

    }