Zig
Zig
Example: Crypt2.DecryptStringENC method
Demonstrates how to call the DecryptStringENC method.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();
crypt.setCryptAlgorithm("aes");
crypt.setCipherMode("cbc");
crypt.setKeyLength(128);
crypt.setEncodedKey("000102030405060708090A0B0C0D0E0F", "hex");
crypt.setEncodedIV("000102030405060708090A0B0C0D0E0F", "hex");
crypt.setEncodingMode("base64");
// Return the base64 encoded encrypted bytes
const encoded_encrypted = try crypt.encryptStringENC(alloc, "Hello World!");
std.debug.print("Encrypted: {s}\n", .{encoded_encrypted});
// Output:
// Encrypted: qiq+IFhcjTkEIkZyf31V/g==
// Decrypt
const original_text = try crypt.decryptStringENC(alloc, encoded_encrypted);
std.debug.print("Decrypted: {s}\n", .{original_text});
// Output:
// Decrypted: Hello World!
}