Sample code for 30+ languages & platforms
Zig

Load a Public Key from a File

Demonstrates the Chilkat PublicKey.LoadFromFile method, which loads a public key from a file. The only argument is the file path. Chilkat examines the file content rather than the extension, accepting binary DER, PEM, Chilkat XML, JWK, and other supported representations.

Note: The file paths are relative to the application's current working directory. Absolute paths may also be used. Supply the paths appropriate to your own environment.

Background: The most convenient loader when a key sits in a file of unknown format — it reads the bytes and detects DER, PEM, XML, or JWK without you having to match a format-specific method. Because it keys off content rather than the filename, a mislabeled extension does not trip it up. This is the pragmatic default for applications that accept public keys from users or varied sources.

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.LoadFromFile method, which loads a public key from a file.  The only
    // argument is the file path.  Chilkat examines the file content (not the extension), accepting
    // binary DER, PEM, Chilkat XML, JWK, and other supported representations.

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

    pub_key.loadFromFile("qa_data/public.pem") 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)});
}