Zig
Zig
Example: Crypt2.ClearEncryptCerts method
Demonstrates how to call the ClearEncryptCerts method.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main() !void {
const crypt = try chilkat.Crypt2.init();
defer crypt.deinit();
// Tell the crypt object to use 3 certificates.
// Do this by calling AddEncryptCert for each certificate.
const cert1 = try chilkat.Cert.init();
defer cert1.deinit();
// ...
// Load the cert from a source such as a .pfx/.p12 file, smart card, USB token, Apple keychain, Windows certificate store, etc.
// ...
crypt.addEncryptCert(cert1);
const cert2 = try chilkat.Cert.init();
defer cert2.deinit();
// ...
crypt.addEncryptCert(cert2);
const cert3 = try chilkat.Cert.init();
defer cert3.deinit();
// ...
crypt.addEncryptCert(cert3);
// Params for public-key encryption to create PKCS7 enveloped-data
crypt.setCryptAlgorithm("pki");
crypt.setPkcs7CryptAlg("aes");
crypt.setKeyLength(256);
crypt.setOaepHash("sha256");
crypt.setOaepPadding(true);
const bd = try chilkat.BinData.init();
defer bd.deinit();
// ...
try crypt.encryptBd(bd);
// Let's say we now want to encrypt something else with different certs..
// First clear the encryption certs.
crypt.clearEncryptCerts();
const cert4 = try chilkat.Cert.init();
defer cert4.deinit();
// ...
crypt.addEncryptCert(cert4);
const cert5 = try chilkat.Cert.init();
defer cert5.deinit();
// ...
crypt.addEncryptCert(cert5);
// ...
// ...
// Encrypt using cert4 and cert5.
try crypt.encryptBd(bd);
}