Sample code for 30+ languages & platforms
Zig Requires Chilkat v11.0.0+

Get Base64 Public Key from Private Key

See more ECC Examples

Demonstrates how to get the public key in base64 format from a private key.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    // Load a private key from base64.
    const bd = try chilkat.BinData.init();
    defer bd.deinit();
    try bd.appendEncoded("MHQCA....n0Q==", "base64");

    const priv_key = try chilkat.PrivateKey.init();
    defer priv_key.deinit();
    priv_key.loadAnyFormat(bd, "") catch {
        std.debug.print("{s}\n", .{try priv_key.getLastErrorText(alloc)});
        return;
    };

    const pub_key = try chilkat.PublicKey.init();
    defer pub_key.deinit();
    priv_key.toPublicKey(pub_key) catch {};

    const pub_key_base64 = try pub_key.getEncoded(alloc, true, "base64");
    std.debug.print("{s}\n", .{pub_key_base64});
}