React Native Requires Chilkat v11.0.0+
React Native
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 React Native Downloads
import { JavaKeyStore, Pfx } from '@chilkat/react-native'
function chilkatExample() {
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const pfx = new Pfx();
// Load the PKCS12 from a file
try {
pfx.loadPfxFile('/someDir/my.p12', 'myPfxPassword');
} catch {
console.log(pfx.lastErrorText);
return;
}
const jksPassword = 'myJksPassword';
const alias = 'firstPrivateKeyAlias';
const 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.
try {
pfx.toJksObj(alias, jksPassword, jks);
} catch {
console.log(pfx.lastErrorText);
return;
}
// Save the Java keystore to a file.
try {
jks.toFile(jksPassword, '/myKeystores/my.jks');
} catch {
console.log(jks.lastErrorText);
return;
}
console.log('Successfully converted PFX to JKS.');
}