(Delphi ActiveX) Get Public Key from Certificate PEM
Loads a certificate from a PEM file and gets the cert's public key.
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Chilkat_TLB;
...
procedure TForm1.Button1Click(Sender: TObject);
var
cert: TChilkatCert;
success: Integer;
pubkey: IPublicKey;
begin
cert := TChilkatCert.Create(Self);
success := cert.LoadFromFile('qa_data/certs/someCert.pem');
if (success <> 1) then
begin
Memo1.Lines.Add(cert.LastErrorText);
Exit;
end;
// Get the certificate's public key:
pubkey := cert.ExportPublicKey();
if (cert.LastMethodSuccess <> 1) then
begin
Memo1.Lines.Add(cert.LastErrorText);
Exit;
end;
Memo1.Lines.Add(pubkey.GetPem(0));
// OK.. we have the public key which can be used in other Chilkat classes/methods...
end;
|