Unicode C
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
#include <C_CkJwsW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkJwsW jws;
HCkJsonObjectW header;
success = FALSE;
jws = CkJwsW_Create();
// Build the JWS protected header. The "alg" member names the signature algorithm.
header = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(header,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 = CkJwsW_SetProtectedHeader(jws,0,header);
if (success == FALSE) {
wprintf(L"%s\n",CkJwsW_lastErrorText(jws));
CkJwsW_Dispose(jws);
CkJsonObjectW_Dispose(header);
return;
}
wprintf(L"Protected header set.\n");
CkJwsW_Dispose(jws);
CkJsonObjectW_Dispose(header);
}