Lua
Lua
AddDetachedSignaturePk
See more MIME Examples
Demonstrates how to add a detached signature using a certifcate and it's corresponding private key. The easiest way of doing it is when both the certificate and private key are contained together within a PFX (.pfx or .p12) file. This example demonstrates how to use the certificate and its corresponding private key when they are stored in separate files -- a .cer for the certificate, and a .pem for the private key.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()
-- Load the certificate from a .cer file.
local cert = chilkat.Cert.new()
local success = cert:load_from_file("aaworkarea/myCert.cer")
if not success then
print(cert.last_error_text)
return
end
-- Load the private key from an encrypted PEM file.
-- (A private key can be loaded from other file formats also..)
local privKey = chilkat.PrivateKey.new()
success = privKey:load_encrypted_pem_file("aaworkarea/myPrivateKey.pem", "myPassword")
if not success then
print(privKey.last_error_text)
return
end
success = mime:set_body_from_plain_text("This is the plain-text MIME body.")
-- Sign the MIME (adds a PKCS7 detached signature)
success = mime:add_detached_signature_pk(cert, privKey)
if not success then
print(mime.last_error_text)
return
end
-- Save the S/MIME to a file.
success = mime:save_mime("aaworkarea/signedMime.txt")
if not success then
print(mime.last_error_text)
return
end
print("success!")