Sample code for 30+ languages & platforms
C

Set the JWS Payload from a StringBuilder

See more JSON Web Signatures (JWS) Examples

Demonstrates Jws.SetPayloadSb, which sets the payload to be signed from a StringBuilder.

Background. JWS (JSON Web Signature) integrity-protects a payload with a signature or MAC. The header alg names the algorithm; this example uses HMAC-SHA256 (HS256) with a symmetric MAC key.

Chilkat C Downloads

C
#include <C_CkJws.h>
#include <C_CkStringBuilder.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkJws jws;
    HCkStringBuilder sbPayload;
    BOOL bIncludeBom;

    success = FALSE;

    jws = CkJws_Create();

    //  Set the payload from a StringBuilder.
    sbPayload = CkStringBuilder_Create();
    CkStringBuilder_Append(sbPayload,"This is the content to sign.");

    bIncludeBom = FALSE;
    success = CkJws_SetPayloadSb(jws,sbPayload,"utf-8",bIncludeBom);
    if (success == FALSE) {
        printf("%s\n",CkJws_lastErrorText(jws));
        CkJws_Dispose(jws);
        CkStringBuilder_Dispose(sbPayload);
        return;
    }

    printf("Payload set.\n");


    CkJws_Dispose(jws);
    CkStringBuilder_Dispose(sbPayload);

    }