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

Example: Mime.GetDecryptCertInfo method

Demonstrates the GetDecryptCertInfo method.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

local mime = chilkat.Mime.new()

-- Load MIME that is has Content-Type like this:
-- Content-Type: application/pkcs7-mime; smime-type="enveloped-data"; name="smime.p7m"; smime-type="enveloped-data"
local success = mime:load_mime_file("qa_data/mime/enveloped_data.eml")
if not success then
    print(mime.last_error_text)
    return
end

-- Get information about the certificate that would be needed to decrypt.
-- An enveloped-data can potentially be decrypted by multiple certificates if it was encrypted in a way that allows it,
-- but in most cases, only a single certificate with associated private key (that of the message recipient) is possible.
local json = chilkat.JsonObject.new()
success = mime:get_decrypt_cert_info(json)
if not success then
    print(mime.last_error_text)
    return
end

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

-- Sample output:

-- {
--   "recipientInfo": [
--     {
--       "serial": "****",
--       "issuerCN": "****"
--     }
--   ]
-- }

-- Get each certificate's information like this:
local serial = ""
local issuerCN = ""

local i = 0
local count = json:size_of_array("recipientInfo")
while i < count do
    json.i = i
    serial = json:string_of("recipientInfo[i].serial")
    issuerCN = json:string_of("recipientInfo[i].issuerCN")
    i = i + 1
end