Sample code for 30+ languages & platforms
Dart Requires Chilkat v10.1.2+

Load PFX/P12 File into Certificate Store Object

Demonstrates how to load a .pfx/.p12 into a certificate store object.

Chilkat Dart Downloads

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

void main() {
  final certStore = CkCertStore();

  // This only loads the contents of the PFX file into the certStore object.
  // It is not importing the PFX into the Windows certificate stores.
  final pfxPassword = 'badssl.com';
  try {
    certStore.loadPfxFile('qa_data/pfx/badssl.com-client.p12', pfxPassword);
  } on ChilkatException catch (e) {
    print(e.lastErrorText);
    return;
  }

  // Examine each certificate (loaded from the PFX) in this certStore object
  final cert = CkCert();
  final numCerts = certStore.numCertificates;
  var i = 0;
  while (i < numCerts) {
    certStore.getCert(i, cert);
    print('hasPrivateKey=${cert.hasPrivateKey()}, ${cert.subjectCN}');
    i++;
  }
}