(Delphi DLL) Get Certificate Public Key from PEM
Demonstrates how to load a PEM file containing a certificate and access the public key.
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Cert, PublicKey;
...
procedure TForm1.Button1Click(Sender: TObject);
var
cert: HCkCert;
success: Boolean;
pubkey: HCkPublicKey;
begin
cert := CkCert_Create();
success := CkCert_LoadFromFile(cert,'qa_data/pem/my_cert.pem');
if (success <> True) then
begin
Memo1.Lines.Add(CkCert__lastErrorText(cert));
Exit;
end;
pubkey := CkCert_ExportPublicKey(cert);
if (CkCert_getLastMethodSuccess(cert) <> True) then
begin
Memo1.Lines.Add(CkCert__lastErrorText(cert));
Exit;
end;
// Examine the public key as XML..
Memo1.Lines.Add(CkPublicKey__getXml(pubkey));
CkPublicKey_Dispose(pubkey);
CkCert_Dispose(cert);
end;
|