Zig
Zig
Convert DSA DER Private Key to PEM
See more DSA Examples
Converts a DSA private key from DER format to PEM. Demonstrates how to write both encrypted and unencrypted PEM formatted private keys.Chilkat Zig Downloads
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 private key.
dsa.fromDerFile("dsa_priv.der") catch {
std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
return;
};
var pem_str: [:0]const u8 = "";
// Save to unencrypted PEM:
pem_str = try dsa.toPem(alloc);
dsa.saveText(pem_str, "dsa_priv.pem") catch {
std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
return;
};
// Save to encrypted PEM:
pem_str = try dsa.toEncryptedPem(alloc, "myPassword");
dsa.saveText(pem_str, "dsa_privEncrypted.pem") catch {
std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
return;
};
std.debug.print("Finished!\n", .{});
}