Sample code for 30+ languages & platforms
Tcl

Convert a PFX to a Java KeyStore

See more PFX/P12 Examples

Demonstrates Pfx.ToJksObj, which populates a JavaKeyStore with a JKS representation of the PFX, then writes it to a file.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. One private-key entry is created for each private key, with certificate chains built from the PFX certificates. The password protects the generated Java KeyStore.

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

set pfx [new_CkPfx]

#  The file path is relative to the application's current working directory.  An absolute path
#  may also be used.  Supply the path appropriate to your own environment.
#  The PFX password should come from a secure source rather than being hard-coded.
set password "myPfxPassword"
set success [CkPfx_LoadPfxFile $pfx "qa_data/identity.pfx" $password]
if {$success == 0} then {
    puts [CkPfx_lastErrorText $pfx]
    delete_CkPfx $pfx
    exit
}

#  Populate a Java KeyStore (JKS) representation of this PFX.  One private-key entry is created for
#  each private key, and the PFX certificates are used to build the certificate chains.  The 1st
#  argument is the alias for the first private-key entry, and the 2nd protects the generated JKS.
#  The JKS password should come from a secure source rather than being hard-coded.
set jksPassword "myJksPassword"
set jks [new_CkJavaKeyStore]

set success [CkPfx_ToJksObj $pfx "myalias" $jksPassword $jks]
if {$success == 0} then {
    puts [CkPfx_lastErrorText $pfx]
    delete_CkPfx $pfx
    delete_CkJavaKeyStore $jks
    exit
}

#  The Java KeyStore object can then be written to a .jks file.
set success [CkJavaKeyStore_ToFile $jks $jksPassword "qa_output/identity.jks"]
if {$success == 0} then {
    puts [CkJavaKeyStore_lastErrorText $jks]
    delete_CkPfx $pfx
    delete_CkJavaKeyStore $jks
    exit
}

puts "Wrote a Java KeyStore with [CkJavaKeyStore_get_NumPrivateKeys $jks] private key(s)."

delete_CkPfx $pfx
delete_CkJavaKeyStore $jks