Sample code for 30+ languages & platforms
Rust

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 Rust Downloads

Rust

let jws = chilkat::Jws::new();

// Load the JWS compact serialization.
let jws_compact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>".to_string();
if jws.load_jws(&jws_compact).is_err() {
    println!("{}", jws.last_error_text());
    return;
}

// Copy the decoded protected header of signature 0 into a JsonObject.
let json = chilkat::JsonObject::new();
if jws.get_protected_h(0, &json).is_err() {
    println!("{}", jws.last_error_text());
    return;
}

json.set_emit_compact(false);
println!("{}", json.emit().unwrap_or_default());