Zig
Zig
Convert DSA PEM Private Key to DER
See more DSA Examples
Converts a DSA private key from PEM format to DER. The first part of the example will convert an unencrypted PEM to DER, then 2nd part will convert an encrypted PEM to unencrypted DER.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 PEM private key.
var pem_private_key: [:0]const u8 = "";
pem_private_key = try dsa.loadText(alloc, "dsa_priv.pem");
// Import the unencrypted PEM into the DSA object.
dsa.fromPem(pem_private_key) catch {
std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
return;
};
// Write it out as a DER file:
dsa.toDerFile("dsa_priv.der") catch {
std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
return;
};
// Load an encrypted PEM private key.
pem_private_key = try dsa.loadText(alloc, "dsa_privEncrypted.pem");
// Import the encrypted PEM into the DSA object.
dsa.fromEncryptedPem("myPassword", pem_private_key) catch {
std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
return;
};
// Write it out as an unencrypted DER file:
dsa.toDerFile("dsa_priv2.der") catch {
std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
return;
};
std.debug.print("Finished!\n", .{});
}