React Native Requires Chilkat v11.0.0+
React Native
Export Digital Certificate's Public Key
See more Certificates Examples
The ExportPublicKey method can be called to get a certificate's public key. It can then be saved to any of a number of formats: (1) OpenSSL DER, (2) OpenSSL PEM, (3) RSA DER, (4) XML.Chilkat React Native Downloads
import { Cert, PublicKey } from '@chilkat/react-native'
function chilkatExample() {
const cert = new Cert();
// LoadFromFile will load virtually any certificate format file.
// It will auto-recognize the format and load appropiately.
try {
cert.loadFromFile('/Users/chilkat/testData/cer/chilkat.cer');
} catch {
console.log(cert.lastErrorText);
return;
}
// Get the public key:
const pubkey = new PublicKey();
cert.getPublicKey(pubkey);
// Save to various formats:
try {
pubkey.saveDerFile(false, '/Users/chilkat/testData/pubkeys/chilkat_pkcs8.der');
} catch {
console.log(pubkey.lastErrorText);
return;
}
try {
pubkey.savePemFile(false, '/Users/chilkat/testData/pubkeys/chilkat.pem');
} catch {
console.log(pubkey.lastErrorText);
return;
}
try {
pubkey.saveDerFile(true, '/Users/chilkat/testData/pubkeys/chilkat_pkcs1.der');
} catch {
console.log(pubkey.lastErrorText);
return;
}
try {
pubkey.saveXmlFile('/Users/chilkat/testData/pubkeys/chilkat.xml');
} catch {
console.log(pubkey.lastErrorText);
return;
}
console.log('Public key exported to all file formats.');
}