Sample code for 30+ languages & platforms
React Native

Convert PKCS12 / PFX to Java KeyStore

See more Java KeyStore (JKS) Examples

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

Chilkat React Native Downloads

React Native
import { JavaKeyStore, Pfx } from '@chilkat/react-native'

function chilkatExample() {
  // This requires the Chilkat API to have been previously unlocked.
  // See Global Unlock Sample for sample code.

  const jks = new JavaKeyStore();

  const pfx = new Pfx();

  const pfxPassword = 'secret';

  // Load a PKCS12 from a file.
  try {
    pfx.loadPfxFile('/someDir/my.p12', pfxPassword);
  } catch {
    console.log(pfx.lastErrorText);
    return;
  }

  const alias = 'someAlias';
  const jksPassword = 'jksSecret';

  // Add the PKCS12 to the empty Java keystore object:
  try {
    jks.addPfx(pfx, alias, jksPassword);
  } catch {
    console.log(jks.lastErrorText);
    return;
  }

  // Write the Java keystore to a file:
  try {
    jks.toFile(jksPassword, '/jksFiles/my.jks');
    console.log('Successfully converted PKCS12 to JKS');
  } catch {
    console.log(jks.lastErrorText);
  }
}