React Native
React Native
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 React Native Downloads
import { JsonObject, Jws } from '@chilkat/react-native'
function chilkatExample() {
const jws = new Jws();
// Load the JWS compact serialization.
const jwsCompact = 'eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>';
try {
jws.loadJws(jwsCompact);
} catch {
console.log(jws.lastErrorText);
return;
}
// Copy the decoded protected header of signature 0 into a JsonObject.
const json = new JsonObject();
try {
jws.getProtectedH(0, json);
} catch {
console.log(jws.lastErrorText);
return;
}
json.emitCompact = false;
console.log(json.emit());
}