Zig
Zig
Generate new DSA Key from OpenSSL Parameters File
See more DSA Examples
Generates a new DSA key from an OpenSSL-created parameters file (DER and PEM formats supported). Examples of using OpenSSL to create parameter files are shown here:openssl dsaparam -outform DER 1024 < seedData.txt >dsaparam.der openssl dsaparam 1024 < seedData.txt >dsaparam.pem
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();
dsa.genKeyFromParamsDerFile("dsaparam.der") catch {
std.debug.print("{s}\n", .{try dsa.getLastErrorText(alloc)});
return;
};
// To generate a key from PEM, call GenKeyFromParamsPem
// (for an in-memory PEM string) or GenKeyFromParamsFilePem
// for a PEM file.
// The public and private keys may now be exported to PEM, DER,
// and XML formatted files.
var pem_str: [:0]const u8 = "";
var xml_str: [:0]const u8 = "";
// First for the public key...
// The public key never needs to be encrypted.
// Save the public key in PEM format:
pem_str = try dsa.toPublicPem(alloc);
// This example will not check the return value of SaveText...
try dsa.saveText(pem_str, "dsa_pub.pem");
// Save the public key in DER format:
try dsa.toPublicDerFile("dsa_pub.der");
var b_public_only: bool = true;
// Save to XML
xml_str = try dsa.toXml(alloc, b_public_only);
try dsa.saveText(pem_str, "dsa_pub.xml");
// ------------------------------------
// Now for the private key....
// ------------------------------------
// Unencrypted PEM:
pem_str = try dsa.toPem(alloc);
try dsa.saveText(pem_str, "dsa_priv.pem");
// Encrypted PEM:
pem_str = try dsa.toEncryptedPem(alloc, "myPassword");
try dsa.saveText(pem_str, "dsa_privEncrypted.pem");
// DER:
try dsa.toDerFile("dsa_priv.der");
// XML:
b_public_only = false;
xml_str = try dsa.toXml(alloc, b_public_only);
try dsa.saveText(pem_str, "dsa_priv.xml");
std.debug.print("Finished!\n", .{});
}