Lua
Lua
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 Lua Downloads
local chilkat = require("chilkat")
local jws = chilkat.Jws.new()
-- Load the JWS compact serialization.
local jwsCompact = "eyJhbGciOiJIUzI1NiJ9.VGhpcyBpcyB0aGUgY29udGVudCB0byBzaWduLg.<signature>"
local success = jws:load_jws(jwsCompact)
if not success then
print(jws.last_error_text)
return
end
-- Copy the decoded protected header of signature 0 into a JsonObject.
local json = chilkat.JsonObject.new()
success = jws:get_protected_h(0, json)
if not success then
print(jws.last_error_text)
return
end
json.emit_compact = false
print(json:emit())