Lua
Lua
Decrypt a .p7m File (using a PFX)
See more Encryption Examples
_LANGUAGE_ sample code showing how to decrypt a .p7m using a .p12 / .pfx certificate w/ private key.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 crypt = chilkat.Crypt2.new()
-- Use a digital certificate and private key from a PFX file (.pfx or .p12).
local pfxPath = "myCertAndKey.pfx"
local pfxPassword = "test123"
local success = crypt:add_pfx_source_file(pfxPath, pfxPassword)
if not success then
print(crypt.last_error_text)
return
end
-- Set the outPath to whatever is appropriate.
-- If you are decrypting a PDF, your output might be "out.pdf"...
local inPath = "smime.p7m"
local outPath = "original.txt"
-- Indicate that we're doing public key decryption (i.e. PKCS7)
crypt.crypt_algorithm = "pki"
success = crypt:ck_decrypt_file(inPath, outPath)
if not success then
print(crypt.last_error_text)
return
end
print("Success.")