Sample code for 30+ languages & platforms
Lua

Duplicate openssl smime -encrypt -binary -aes-256-cbc -in some_file.dat -out some_file.dat.enc -outform DER cert.crt

See more OpenSSL Examples

Demonstrates how to encrypt to binary DER using 256-bit AES (CBC mode) as the underlying symmetric encryption algorithm, to produce PKCS7 enveloped data (binary DER).

Duplicates the following openssl command:

openssl smime -encrypt -binary -aes-256-cbc -in some_file.dat -out some_file.dat.enc -outform DER cert.crt

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local cert = chilkat.Cert.new()
local success = cert:load_from_file("qa_data/openssl/EE.cer")
if not success then
    print(cert.last_error_text)
    return
end

local bd = chilkat.BinData.new()
success = bd:load_file("qa_data/openssl/hello.txt")
-- Assuming success..

local crypt = chilkat.Crypt2.new()
success = crypt:set_encrypt_cert(cert)
if not success then
    print(crypt.last_error_text)
    return
end

crypt.crypt_algorithm = "PKI"

-- Indicate the underlying symmetric encryption to be used:
crypt.pkcs7_crypt_alg = "aes"
crypt.key_length = 256
crypt.cipher_mode = "cbc"

success = crypt:ck_encrypt_file("qa_data/openssl/hello.txt", "qa_output/hello.txt.enc")
if not success then
    print(crypt.last_error_text)
    return
end

print("Success.")