Zig
Zig
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 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 crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
// Use a digital certificate and private key from a PFX file (.pfx or .p12).
const pfx_path = "myCertAndKey.pfx";
const pfx_password = "test123";
crypt.addPfxSourceFile(pfx_path, pfx_password) catch {
std.debug.print("{s}\n", .{try crypt.getLastErrorText(alloc)});
return;
};
// Set the outPath to whatever is appropriate.
// If you are decrypting a PDF, your output might be "out.pdf"...
const in_path = "smime.p7m";
const out_path = "original.txt";
// Indicate that we're doing public key decryption (i.e. PKCS7)
crypt.setCryptAlgorithm("pki");
crypt.ckDecryptFile(in_path, out_path) catch {
std.debug.print("{s}\n", .{try crypt.getLastErrorText(alloc)});
return;
};
std.debug.print("Success.\n", .{});
}