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 <CkJwe.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkJwe jwe;

    //  Load the JWE.
    const char *jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>";
    success = jwe.LoadJwe(jweCompact);
    if (success == false) {
        std::cout << jwe.lastErrorText() << "\r\n";
        return;
    }

    //  Copy the entire loaded JWE structure into a JsonObject.  This is the full JWE representation, not a
    //  decoded or merged JOSE header.
    CkJsonObject json;
    success = jwe.GetHeader(json);
    if (success == false) {
        std::cout << jwe.lastErrorText() << "\r\n";
        return;
    }

    json.put_EmitCompact(false);
    std::cout << json.emit() << "\r\n";
    }