PHP Requires Chilkat v11.0.0+
PHP
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 PHP Downloads
<?php
use Chilkat2\JavaKeyStore;
use Chilkat2\Pfx;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
$pfx = new Pfx();
// Load the PKCS12 from a file
try {
$pfx->LoadPfxFile('/someDir/my.p12', 'myPfxPassword');
$jksPassword = 'myJksPassword';
$alias = 'firstPrivateKeyAlias';
$jks = new JavaKeyStore();
// 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, $jksPassword, $jks);
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
// Save the Java keystore to a file.
try {
$jks->ToFile($jksPassword, '/myKeystores/my.jks');
} catch (\Chilkat2\Exception $e) {
echo $e->getMessage(), "\n";
exit;
}
echo "Successfully converted PFX to JKS.\n";