Sample code for 30+ languages & platforms
C

Get the Entire Loaded JWE Structure

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.GetHeader, which copies the entire currently loaded JWE structure into a JsonObject.

Background. This is the full JWE representation, not a decoded or merged JOSE header. It can contain the protected, unprotected, and per-recipient header material.

Chilkat C Downloads

C
#include <C_CkJwe.h>
#include <C_CkJsonObject.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkJwe jwe;
    const char *jweCompact;
    HCkJsonObject json;

    success = FALSE;

    jwe = CkJwe_Create();

    //  Load the JWE.
    jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>";
    success = CkJwe_LoadJwe(jwe,jweCompact);
    if (success == FALSE) {
        printf("%s\n",CkJwe_lastErrorText(jwe));
        CkJwe_Dispose(jwe);
        return;
    }

    //  Copy the entire loaded JWE structure into a JsonObject.  This is the full JWE representation, not a
    //  decoded or merged JOSE header.
    json = CkJsonObject_Create();
    success = CkJwe_GetHeader(jwe,json);
    if (success == FALSE) {
        printf("%s\n",CkJwe_lastErrorText(jwe));
        CkJwe_Dispose(jwe);
        CkJsonObject_Dispose(json);
        return;
    }

    CkJsonObject_putEmitCompact(json,FALSE);
    printf("%s\n",CkJsonObject_emit(json));


    CkJwe_Dispose(jwe);
    CkJsonObject_Dispose(json);

    }