Sample code for 30+ languages & platforms
PHP

Convert PKCS12 / PFX to Java KeyStore

See more Java KeyStore (JKS) Examples

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

Chilkat PHP Downloads

PHP
<?php

use Chilkat2\JavaKeyStore;
use Chilkat2\Pfx;

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

$jks = new JavaKeyStore();

$pfx = new Pfx();

$pfxPassword = 'secret';

// Load a PKCS12 from a file.
try {
    $pfx->LoadPfxFile('/someDir/my.p12', $pfxPassword);

    $alias = 'someAlias';
    $jksPassword = 'jksSecret';

    // Add the PKCS12 to the empty Java keystore object:
    $jks->AddPfx($pfx, $alias, $jksPassword);
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
    exit;
}

// Write the Java keystore to a file:
try {
    $jks->ToFile($jksPassword, '/jksFiles/my.jks');
    echo "Successfully converted PKCS12 to JKS\n";
} catch (\Chilkat2\Exception $e) {
    echo $e->getMessage(), "\n";
}