Sample code for 30+ languages & platforms
Zig

Load a Public Key from Base64 DER

Demonstrates the Chilkat PublicKey.LoadBase64 method, which loads a public key from standard Base64-encoded DER. The only argument is the Base64 string; whitespace within it is permitted.

Background: A public key in DER (binary) form is often carried as Base64 text so it can travel through channels that expect a string — a config value, a JSON field, a certificate export. This loader decodes that text and inspects the DER to determine the key type and structure automatically. It is the plain-Base64 counterpart to loading a full PEM block, which additionally has the BEGIN/END armor.

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();

    // Demonstrates the PublicKey.LoadBase64 method, which loads a public key from standard
    // Base64-encoded DER.  The only argument is the Base64 string (whitespace is allowed).

    const pub_key = try chilkat.PublicKey.init();
    defer pub_key.deinit();

    // The Base64 of the DER-encoded public key.
    const key_str = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA...IDAQAB";

    pub_key.loadBase64(key_str) catch {
        std.debug.print("{s}\n", .{try pub_key.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Loaded a {s} public key.\n", .{try pub_key.getKeyType(alloc)});
}