Dart
Dart
Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx
See more OpenSSL Examples
How to create a PKCS12 (.p12 or .pfx) from a certificate file and private key file: Demonstrates how to duplicate this OpenSSL command:Duplicate openssl pkcs12 –export –in certfile.cer –inkey certfile.key –out certfile.pfx
Chilkat Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
final pkey = CkPrivateKey();
// Load the private key from the file.
try {
pkey.loadAnyFormatFile('certFile.key', '');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
final cert = CkCert();
// The LoadFromFile method auto-recognizes the format...
try {
cert.loadFromFile('certfile.cer');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// We'll need a cert chain object to create the PKCS12, so get it
// from the cert.
final CkCertChain certChain;
try {
certChain = cert.getCertChain();
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Create the PFX object, add the cert and private key, and write to a .pfx file.
final pfx = CkPfx();
// The cert(s) are automatically added in the call to AddPrivateKey
try {
pfx.addPrivateKey(pkey, certChain);
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Write the .pfx to a file.
final password = 'myPassword';
try {
pfx.toFile(password, 'certfile.pfx');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Success.');
}