Sample code for 30+ languages & platforms
Unicode C++

Set the JWS Protected Header

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.SetProtectedHeader, which sets the integrity-protected header for a signer from a JsonObject. The header specifies the signature algorithm (alg).

Background. The protected header is covered by the signature, so it cannot be altered without invalidating the JWS. It is configured before creating the JWS.

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkJwsW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

    CkJwsW jws;

    //  Build the JWS protected header.  The "alg" member names the signature algorithm.
    CkJsonObjectW header;
    header.UpdateString(L"alg",L"HS256");

    //  Set the protected header for signer index 0.  The protected header is integrity-protected: it is
    //  covered by the signature.
    success = jws.SetProtectedHeader(0,header);
    if (success == false) {
        wprintf(L"%s\n",jws.lastErrorText());
        return;
    }

    wprintf(L"Protected header set.\n");
    }