Sample code for 30+ languages & platforms
Rust

Convert PKCS12 / PFX to Java KeyStore

See more Java KeyStore (JKS) Examples

Converts a PKCS12 / PFX file to a Java keystore (JKS) file.

Chilkat Rust Downloads

Rust

// This requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

let jks = chilkat::JavaKeyStore::new();

let pfx = chilkat::Pfx::new();

let pfx_password = "secret".to_string();

// Load a PKCS12 from a file.
if pfx.load_pfx_file("/someDir/my.p12", &pfx_password).is_err() {
    println!("{}", pfx.last_error_text());
    return;
}

let alias = "someAlias".to_string();
let jks_password = "jksSecret".to_string();

// Add the PKCS12 to the empty Java keystore object:
if jks.add_pfx(&pfx, &alias, &jks_password).is_err() {
    println!("{}", jks.last_error_text());
    return;
}

// Write the Java keystore to a file:
if jks.to_file(&jks_password, "/jksFiles/my.jks").is_err() {
    println!("{}", jks.last_error_text());
} else {
    println!("Successfully converted PKCS12 to JKS");
}