Zig
Zig
Convert PKCS12 / PFX to Java KeyStore
See more Java KeyStore (JKS) Examples
Converts a PKCS12 / PFX file to a Java keystore (JKS) file.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
var success: bool = false;
// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const jks = try chilkat.JavaKeyStore.init();
defer jks.deinit();
const pfx = try chilkat.Pfx.init();
defer pfx.deinit();
const pfx_password = "secret";
// Load a PKCS12 from a file.
success = if (pfx.loadPfxFile("/someDir/my.p12", pfx_password)) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try pfx.getLastErrorText(alloc)});
return;
}
const alias = "someAlias";
const jks_password = "jksSecret";
// Add the PKCS12 to the empty Java keystore object:
success = if (jks.addPfx(pfx, alias, jks_password)) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try jks.getLastErrorText(alloc)});
return;
}
// Write the Java keystore to a file:
success = if (jks.toFile(jks_password, "/jksFiles/my.jks")) true else |_| false;
if (!success) {
std.debug.print("{s}\n", .{try jks.getLastErrorText(alloc)});
} else {
std.debug.print("Successfully converted PKCS12 to JKS\n", .{});
}
}