Dart Requires Chilkat v11.0.0+
Dart
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 Dart Downloads
import 'package:chilkat/chilkat.dart';
void main() {
final cert = CkCert();
// 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');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
// Get the public key:
final pubkey = CkPublicKey();
cert.getPublicKey(pubkey);
// Save to various formats:
try {
pubkey.saveDerFile(false, '/Users/chilkat/testData/pubkeys/chilkat_pkcs8.der');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
pubkey.savePemFile(false, '/Users/chilkat/testData/pubkeys/chilkat.pem');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
pubkey.saveDerFile(true, '/Users/chilkat/testData/pubkeys/chilkat_pkcs1.der');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
try {
pubkey.saveXmlFile('/Users/chilkat/testData/pubkeys/chilkat.xml');
} on ChilkatException catch (e) {
print(e.lastErrorText);
return;
}
print('Public key exported to all file formats.');
}