C
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 C Downloads
#include <C_CkJwe.h>
#include <C_CkJsonObject.h>
void ChilkatSample(void)
{
BOOL success;
HCkJwe jwe;
const char *jweCompact;
HCkJsonObject json;
success = FALSE;
jwe = CkJwe_Create();
// Load the JWE.
jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>";
success = CkJwe_LoadJwe(jwe,jweCompact);
if (success == FALSE) {
printf("%s\n",CkJwe_lastErrorText(jwe));
CkJwe_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 = CkJsonObject_Create();
success = CkJwe_GetProtectedHeader(jwe,json);
if (success == FALSE) {
printf("%s\n",CkJwe_lastErrorText(jwe));
CkJwe_Dispose(jwe);
CkJsonObject_Dispose(json);
return;
}
CkJsonObject_putEmitCompact(json,FALSE);
printf("%s\n",CkJsonObject_emit(json));
CkJwe_Dispose(jwe);
CkJsonObject_Dispose(json);
}