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 <CkJwe.h>
#include <CkJsonObject.h>
void ChilkatSample(void)
{
bool success = false;
CkJwe jwe;
// Load the JWE.
const char *jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>";
success = jwe.LoadJwe(jweCompact);
if (success == false) {
std::cout << jwe.lastErrorText() << "\r\n";
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.
CkJsonObject json;
success = jwe.GetProtectedHeader(json);
if (success == false) {
std::cout << jwe.lastErrorText() << "\r\n";
return;
}
json.put_EmitCompact(false);
std::cout << json.emit() << "\r\n";
}