Sample code for 30+ languages & platforms
Lua

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

Lua
local chilkat = require("chilkat")

local jwe = chilkat.Jwe.new()

-- Load the JWE.
local jweCompact = "eyJhbGciOiJBMjU2S1ciLCJlbmMiOiJBMjU2R0NNIn0.<...>.<iv>.<ciphertext>.<tag>"
local success = jwe:load_jwe(jweCompact)
if not success then
    print(jwe.last_error_text)
    return
end

-- 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.
local json = chilkat.JsonObject.new()
success = jwe:get_protected_header(json)
if not success then
    print(jwe.last_error_text)
    return
end

json.emit_compact = false
print(json:emit())