Sample code for 30+ languages & platforms
Dart

Convert PKCS12 / PFX to Java KeyStore

See more Java KeyStore (JKS) Examples

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

Chilkat Dart Downloads

Dart
import 'package:chilkat/chilkat.dart';

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

  final jks = CkJavaKeyStore();

  final pfx = CkPfx();

  final pfxPassword = 'secret';

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

  final alias = 'someAlias';
  final jksPassword = 'jksSecret';

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

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