Sample code for 30+ languages & platforms
Swift

Get the JWE Protected Header

See more JSON Web Encryption (JWE) Examples

Demonstrates Jwe.GetProtectedHeader, which copies the decoded shared JWE protected header into a JsonObject.

Background. Only the protected header is returned; it is not merged with the shared unprotected header or any per-recipient header.

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 decoded shared JWE protected header into a JsonObject.  Only the protected header is
    //  returned; it is not merged with the unprotected or per-recipient headers.
    let json = CkoJsonObject()!
    success = jwe.getProtectedHeader(json: json)
    if success == false {
        print("\(jwe.lastErrorText!)")
        return
    }

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

}