Zig
Zig
PKCS7 Decrypt MIME
See more MIME Examples
Loads a PKCS7 encrypted MIME file and decrypts. The cert and private key used for decryption is loaded from a PFX file.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 mime = try chilkat.Mime.init();
defer mime.deinit();
// Load the MIME
mime.loadMimeFile("encryptedMime.txt") catch {
std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
return;
};
// The AddPfxSourceFile and/or AddPfxSourceData
// methods may be called one or more times (one per PFX)
// to add sources from which the MIME component will
// search for certificates and private keys when decrypting.
const pfx_password = "myPassword";
mime.addPfxSourceFile("myCertAndPrivateKey.pfx", pfx_password) catch {
std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
return;
};
// Decrypt...
mime.decrypt() catch {
std.debug.print("{s}\n", .{try mime.getLastErrorText(alloc)});
return;
};
// Display the decrypted MIME:
std.debug.print("{s}\n", .{try mime.getMime(alloc)});
}