Perl
Perl
Convert PKCS12 / PFX to Java KeyStore
See more Java KeyStore (JKS) Examples
Converts a PKCS12 / PFX file to a Java keystore (JKS) file.Chilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
# This requires the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
my $jks = Chilkat2::JavaKeyStore->new;
my $pfx = Chilkat2::Pfx->new;
my $pfxPassword = 'secret';
# Load a PKCS12 from a file.
my $success = $pfx->LoadPfxFile('/someDir/my.p12', $pfxPassword);
if (!$success) {
print $pfx->LastErrorText, "\n";
exit;
}
my $alias = 'someAlias';
my $jksPassword = 'jksSecret';
# Add the PKCS12 to the empty Java keystore object:
$success = $jks->AddPfx($pfx, $alias, $jksPassword);
if (!$success) {
print $jks->LastErrorText, "\n";
exit;
}
# Write the Java keystore to a file:
$success = $jks->ToFile($jksPassword, '/jksFiles/my.jks');
if (!$success) {
print $jks->LastErrorText, "\n";
} else {
print "Successfully converted PKCS12 to JKS\n";
}