Unicode C
Unicode C
Set the JWE Protected Header
See more JSON Web Encryption (JWE) Examples
Demonstrates Jwe.SetProtectedHeader, which sets the integrity-protected JWE header from a JsonObject. The header specifies the key-management algorithm (alg) and content-encryption algorithm (enc).
Background. The protected header is integrity-protected and applies to all recipients. It is configured before encrypting.
Chilkat Unicode C Downloads
#include <C_CkJweW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkJweW jwe;
HCkJsonObjectW header;
success = FALSE;
jwe = CkJweW_Create();
// Build the JWE protected header. The "alg" member names the key-management algorithm and the "enc"
// member names the content-encryption algorithm.
header = CkJsonObjectW_Create();
CkJsonObjectW_UpdateString(header,L"alg",L"A256KW");
CkJsonObjectW_UpdateString(header,L"enc",L"A256GCM");
// Set the protected header on the JWE. The protected header is integrity-protected and applies to
// all recipients.
success = CkJweW_SetProtectedHeader(jwe,header);
if (success == FALSE) {
wprintf(L"%s\n",CkJweW_lastErrorText(jwe));
CkJweW_Dispose(jwe);
CkJsonObjectW_Dispose(header);
return;
}
wprintf(L"Protected header set.\n");
CkJweW_Dispose(jwe);
CkJsonObjectW_Dispose(header);
}