React Native
React Native
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 React Native Downloads
import { Cert, CertChain, Pfx, PrivateKey } from '@chilkat/react-native'
function chilkatExample() {
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const pkey = new PrivateKey();
// Load the private key from the file.
try {
pkey.loadAnyFormatFile('certFile.key', '');
} catch {
console.log(pkey.lastErrorText);
return;
}
const cert = new Cert();
// The LoadFromFile method auto-recognizes the format...
try {
cert.loadFromFile('certfile.cer');
} catch {
console.log(cert.lastErrorText);
return;
}
// We'll need a cert chain object to create the PKCS12, so get it
// from the cert.
let certChain: CertChain;
try {
certChain = cert.getCertChain();
} catch {
console.log(cert.lastErrorText);
return;
}
// Create the PFX object, add the cert and private key, and write to a .pfx file.
const pfx = new Pfx();
// The cert(s) are automatically added in the call to AddPrivateKey
try {
pfx.addPrivateKey(pkey, certChain);
} catch {
console.log(pfx.lastErrorText);
return;
}
// Write the .pfx to a file.
const password = 'myPassword';
try {
pfx.toFile(password, 'certfile.pfx');
} catch {
console.log(pfx.lastErrorText);
return;
}
console.log('Success.');
}