Lua
Lua
PKCS7 Decrypt MIME
See more MIME Examples
Loads a PKCS7 encrypted MIME file and decrypts. The cert and private key used for decryption is loaded from a PFX file.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local mime = chilkat.Mime.new()
-- Load the MIME
local success = mime:load_mime_file("encryptedMime.txt")
if not success then
print(mime.last_error_text)
return
end
-- The AddPfxSourceFile and/or AddPfxSourceData
-- methods may be called one or more times (one per PFX)
-- to add sources from which the MIME component will
-- search for certificates and private keys when decrypting.
local pfxPassword = "myPassword"
success = mime:add_pfx_source_file("myCertAndPrivateKey.pfx", pfxPassword)
if not success then
print(mime.last_error_text)
return
end
-- Decrypt...
success = mime:decrypt()
if not success then
print(mime.last_error_text)
return
end
-- Display the decrypted MIME:
print(mime:get_mime())