(Delphi ActiveX) Get Base64 Public Key from Private Key
Demonstrates how to get the public key in base64 format from a private 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
bd: TChilkatBinData;
success: Integer;
privKey: TPrivateKey;
pubKey: IPublicKey;
pubKeyBase64: WideString;
begin
// Load a private key from base64.
bd := TChilkatBinData.Create(Self);
success := bd.AppendEncoded('MHQCA....n0Q==','base64');
privKey := TPrivateKey.Create(Self);
success := privKey.LoadAnyFormat(bd.ControlInterface,'');
if (success = 0) then
begin
Memo1.Lines.Add(privKey.LastErrorText);
Exit;
end;
pubKey := privKey.GetPublicKey();
if (privKey.LastMethodSuccess = 0) then
begin
Memo1.Lines.Add(privKey.LastErrorText);
Exit;
end;
pubKeyBase64 := pubKey.GetEncoded(1,'base64');
Memo1.Lines.Add(pubKeyBase64);
end;
|