Sample code for 30+ languages & platforms
Zig

DSA Public Key PEM to DER Conversion

See more DSA Examples

Converts a DSA public key from PEM format to DER.

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 PEM public key.
    const pem_public_key = try dsa.loadText(alloc, "dsa_pub.pem");
    // Import the public key PEM into the DSA object.
    dsa.fromPublicPem(pem_public_key) catch {
        std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
        return;
    };

    // Write it out as a DER file:
    dsa.toPublicDerFile("dsa_pub.der") catch {
        std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
        return;
    };

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