Zig Requires Chilkat v11.0.0+
Zig
RSA Import Public Key from Certificate PEM
See more RSA Examples
Uses a certificate's public key for RSA encryption. The public key from the certificate .pem file is used.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
const cert = try chilkat.Cert.init();
defer cert.deinit();
cert.loadFromFile("qa_data/pem/mf_public_rsa.pem") catch {
std.debug.print("{s}\n", .{try cert.getLastErrorText(alloc)});
return;
};
const pub_key = try chilkat.PublicKey.init();
defer pub_key.deinit();
cert.getPublicKey(pub_key) catch {};
const rsa = try chilkat.Rsa.init();
defer rsa.deinit();
rsa.usePublicKey(pub_key) catch {};
rsa.setEncodingMode("base64");
const encrypted_str = try rsa.encryptStringENC(alloc, "hello", false);
std.debug.print("encrypted string = {s}\n", .{encrypted_str});
}