Unicode C
Unicode C
Get the JWE Protected Header
See more JSON Web Encryption (JWE) Examples
Demonstrates Jwe.GetProtectedHeader, which copies the decoded shared JWE protected header into a JsonObject.
Background. Only the protected header is returned; it is not merged with the shared unprotected header or any per-recipient header.
Chilkat Unicode C Downloads
#include <C_CkJweW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkJweW jwe;
const wchar_t *jweCompact;
HCkJsonObjectW json;
success = FALSE;
jwe = CkJweW_Create();
// Load the JWE.
jweCompact = L"eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>";
success = CkJweW_LoadJwe(jwe,jweCompact);
if (success == FALSE) {
wprintf(L"%s\n",CkJweW_lastErrorText(jwe));
CkJweW_Dispose(jwe);
return;
}
// Copy the decoded shared JWE protected header into a JsonObject. Only the protected header is
// returned; it is not merged with the unprotected or per-recipient headers.
json = CkJsonObjectW_Create();
success = CkJweW_GetProtectedHeader(jwe,json);
if (success == FALSE) {
wprintf(L"%s\n",CkJweW_lastErrorText(jwe));
CkJweW_Dispose(jwe);
CkJsonObjectW_Dispose(json);
return;
}
CkJsonObjectW_putEmitCompact(json,FALSE);
wprintf(L"%s\n",CkJsonObjectW_emit(json));
CkJweW_Dispose(jwe);
CkJsonObjectW_Dispose(json);
}