Zig
Zig
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 Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const cert = try chilkat.Cert.init();
defer cert.deinit();
cert.loadFromFile("qa_data/openssl/EE.cer") catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
};
const bd = try chilkat.BinData.init();
defer bd.deinit();
try bd.loadFile("qa_data/openssl/hello.txt");
// Assuming success..
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
crypt.setEncryptCert(cert) catch {
std.debug.print("{s}\n", .{try crypt.getLastErrorText(alloc)});
return;
};
crypt.setCryptAlgorithm("PKI");
// Indicate the underlying symmetric encryption to be used:
crypt.setPkcs7CryptAlg("aes");
crypt.setKeyLength(256);
crypt.setCipherMode("cbc");
crypt.ckEncryptFile("qa_data/openssl/hello.txt", "qa_output/hello.txt.enc") catch {
std.debug.print("{s}\n", .{try crypt.getLastErrorText(alloc)});
return;
};
std.debug.print("Success.\n", .{});
}