Zig Requires Chilkat v11.0.0+
Zig
Convert PKCS12 / PFX to Java Keystore (JKS)
See more PFX/P12 Examples
Loads a PKCS12 / PFX file and saves it 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();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const pfx = try chilkat.Pfx.init();
defer pfx.deinit();
// Load the PKCS12 from a file
pfx.loadPfxFile("/someDir/my.p12", "myPfxPassword") catch {
std.debug.print("{s}\n", .{try pfx.getLastErrorText(alloc)});
return;
};
const jks_password = "myJksPassword";
const alias = "firstPrivateKeyAlias";
const jks = try chilkat.JavaKeyStore.init();
defer jks.deinit();
// Convert to a Java keystore object.
// The jksPassword is the password to be used for the JKS private key entries.
// It may be the same as the PFX password, but can also be different if desired.
pfx.toJksObj(alias, jks_password, jks) catch {
std.debug.print("{s}\n", .{try pfx.getLastErrorText(alloc)});
return;
};
// Save the Java keystore to a file.
jks.toFile(jks_password, "/myKeystores/my.jks") catch {
std.debug.print("{s}\n", .{try jks.getLastErrorText(alloc)});
return;
};
std.debug.print("Successfully converted PFX to JKS.\n", .{});
}