Zig Requires Chilkat v11.0.0+
Zig
Use Base64 RSA Key to Encrypt
See more RSA Examples
Loads a Base64 RSA key and uses it to encrypt a string, returning the result in base64.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 pubkey = try chilkat.PublicKey.init();
defer pubkey.deinit();
pubkey.loadBase64("MIICdgIBADA ... A9PXLk+j5A==") catch {
std.debug.print("{s}\n", .{try pubkey.getLastErrorText(alloc)});
return;
};
const rsa = try chilkat.Rsa.init();
defer rsa.deinit();
rsa.usePublicKey(pubkey) catch {
std.debug.print("{s}\n", .{try rsa.getLastErrorText(alloc)});
return;
};
rsa.setEncodingMode("base64");
const encrypted_str = try rsa.encryptStringENC(alloc, "12345678", false);
std.debug.print("{s}\n", .{encrypted_str});
}