Sample code for 30+ languages & platforms
Delphi DLL Requires Chilkat v11.0.0+

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 Delphi DLL Downloads

Delphi DLL
var
success: Boolean;
cert: HCkCert;
pubkey: HCkPublicKey;

begin
success := False;

cert := CkCert_Create();

//  LoadFromFile will load virtually any certificate format file.
//  It will auto-recognize the format and load appropiately.
success := CkCert_LoadFromFile(cert,'/Users/chilkat/testData/cer/chilkat.cer');
if (success = False) then
  begin
    Memo1.Lines.Add(CkCert__lastErrorText(cert));
    Exit;
  end;

//  Get the public key:
pubkey := CkPublicKey_Create();
CkCert_GetPublicKey(cert,pubkey);

//  Save to various formats:
success := CkPublicKey_SaveDerFile(pubkey,False,'/Users/chilkat/testData/pubkeys/chilkat_pkcs8.der');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkPublicKey__lastErrorText(pubkey));
    Exit;
  end;

success := CkPublicKey_SavePemFile(pubkey,False,'/Users/chilkat/testData/pubkeys/chilkat.pem');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkPublicKey__lastErrorText(pubkey));
    Exit;
  end;

success := CkPublicKey_SaveDerFile(pubkey,True,'/Users/chilkat/testData/pubkeys/chilkat_pkcs1.der');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkPublicKey__lastErrorText(pubkey));
    Exit;
  end;

success := CkPublicKey_SaveXmlFile(pubkey,'/Users/chilkat/testData/pubkeys/chilkat.xml');
if (success <> True) then
  begin
    Memo1.Lines.Add(CkPublicKey__lastErrorText(pubkey));
    Exit;
  end;
Memo1.Lines.Add('Public key exported to all file formats.');

CkCert_Dispose(cert);
CkPublicKey_Dispose(pubkey);