Sample code for 30+ languages & platforms
Swift

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

Swift

func chilkatTest() {
    var success: Bool = false

    let jwe = CkoJwe()!

    //  Load the JWE.
    var jweCompact: String? = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>"
    success = jwe.load(jwe: jweCompact)
    if success == false {
        print("\(jwe.lastErrorText!)")
        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 = CkoJsonObject()!
    success = jwe.getHeader(json: json)
    if success == false {
        print("\(jwe.lastErrorText!)")
        return
    }

    json.emitCompact = false
    print("\(json.emit()!)")

}