Sample code for 30+ languages & platforms
Lua Requires Chilkat v11.0.0+

Get Certificate's Public Key

Loads a certificate from PEM and gets the public key.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local cert = chilkat.Cert.new()

local strPem = "-----BEGIN CERTIFICATE----- ..."

local success = cert:load_pem(strPem)
if not success then
    print(cert.last_error_text)
    return
end

local pubKey = chilkat.PublicKey.new()
cert:get_public_key(pubKey)

-- You can now use the public key object however it is needed,
-- and access its various properties and methods..

print(pubKey:get_xml())