Sample code for 30+ languages & platforms
Zig

Convert DSA Public Key DER to PEM

See more DSA Examples

Converts a DSA public key from DER format to PEM.

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

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    const dsa = try chilkat.Dsa.init();
    defer dsa.deinit();

    // Load a DER public key.
    dsa.fromPublicDerFile("dsa_pub.der") catch {
        std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
        return;
    };

    // Save the public key to PEM:
    const pem_str = try dsa.toPublicPem(alloc);
    dsa.saveText(pem_str, "dsa_pub.pem") catch {
        std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("Finished!\n", .{});
}