React Native Requires Chilkat v11.0.0+
React Native
Load PKCS12 / PFX and Access Contents
See more PFX/P12 Examples
Loads a PKCS12 / PFX file and iterates over the contents which include private keys and certificates.Chilkat React Native Downloads
import { Cert, Pfx, PrivateKey } from '@chilkat/react-native'
function chilkatExample() {
const pfx = new Pfx();
// Load the PKCS12 from a file
try {
pfx.loadPfxFile('/someDir/my.p12', 'pfxFilePassword');
} catch {
console.log(pfx.lastErrorText);
return;
}
const numPrivateKeys = pfx.numPrivateKeys;
const privKey = new PrivateKey();
console.log('Private Keys:');
let i = 0;
while (i < numPrivateKeys) {
pfx.privateKeyAt(i, privKey);
// Do something with the private key ...
i++;
}
const cert = new Cert();
const numCerts = pfx.numCerts;
console.log('Certs:');
i = 0;
while (i < numCerts) {
pfx.certAt(i, cert);
console.log(cert.subjectDN);
// If the certificate has a private key (one of the private keys within the PFX)
// then it can also be obtained via the certificate object:
if (cert.hasPrivateKey()) {
console.log('Has private key!');
cert.getPrivateKey(privKey);
// ...
}
i++;
}
}