Lua
Lua
Extract PKCS7 from MIME and Decrypt
See more MIME Examples
Extracts the base64-encoded PKCS7 body of a MIME message to a file, and then decrypts using Chilkat Crypt2.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local mime = chilkat.Mime.new()
local success = mime:load_mime_file("c:/aaworkarea/EmailInBytes.txt")
if not success then
print(mime.last_error_text)
return
end
success = mime:save_body("c:/aaworkarea/smime.p7m")
if not success then
print(mime.last_error_text)
return
end
local crypt = chilkat.Crypt2.new()
success = crypt:add_pfx_source_file("c:/aaworkarea/my.pfx", "pfxPassword")
if not success then
print(crypt.last_error_text)
return
end
-- Indicate the public-key (PKCS7) encryption/decryption should be used:
crypt.crypt_algorithm = "pki"
local inPath = "c:/aaworkarea/smime.p7m"
local outPath = "c:/aaworkarea/decrypted.dat"
success = crypt:ck_decrypt_file(inPath, outPath)
if not success then
print(crypt.last_error_text)
return
end
print("Success.")