C++
C++
Get a JWS Protected Header
See more JSON Web Signatures (JWS) Examples
Demonstrates Jws.GetProtectedH, which copies the decoded protected header of a signature into a JsonObject.
Background. The protected header is integrity-protected by the signature. Inspecting it (for example the
alg value) is useful before deciding how to validate.Chilkat C++ Downloads
#include <CkJws.h>
#include <CkJsonObject.h>
void ChilkatSample(void)
{
bool success = false;
CkJws jws;
// Load the JWS compact serialization.
const char *jwsCompact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>";
success = jws.LoadJws(jwsCompact);
if (success == false) {
std::cout << jws.lastErrorText() << "\r\n";
return;
}
// Copy the decoded protected header of signature 0 into a JsonObject.
CkJsonObject json;
success = jws.GetProtectedH(0,json);
if (success == false) {
std::cout << jws.lastErrorText() << "\r\n";
return;
}
json.put_EmitCompact(false);
std::cout << json.emit() << "\r\n";
}