(Delphi ActiveX) Get Certificate's Public Key
Loads a certificate from PEM and gets the 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;
strPem: WideString;
success: Integer;
pubKey: IPublicKey;
begin
cert := TChilkatCert.Create(Self);
strPem := '-----BEGIN CERTIFICATE----- ...';
success := cert.LoadPem(strPem);
if (success <> 1) then
begin
Memo1.Lines.Add(cert.LastErrorText);
Exit;
end;
pubKey := cert.ExportPublicKey();
if (cert.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(cert.LastErrorText);
Exit;
end;
// You can now use the public key object however it is needed,
// and access its various properties and methods..
Memo1.Lines.Add(pubKey.GetXml());
end;
|