Sample code for 30+ languages & platforms
Rust

Get the Entire Loaded JWE Structure

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.GetHeader, which copies the entire currently loaded JWE structure into a JsonObject.

Background. This is the full JWE representation, not a decoded or merged JOSE header. It can contain the protected, unprotected, and per-recipient header material.

Chilkat Rust Downloads

Rust

let jwe = chilkat::Jwe::new();

// Load the JWE.
let jwe_compact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>".to_string();
if jwe.load_jwe(&jwe_compact).is_err() {
    println!("{}", jwe.last_error_text());
    return;
}

// Copy the entire loaded JWE structure into a JsonObject.  This is the full JWE representation, not a
// decoded or merged JOSE header.
let json = chilkat::JsonObject::new();
if jwe.get_header(&json).is_err() {
    println!("{}", jwe.last_error_text());
    return;
}

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