Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

Duplicate openssl pkey -in private.pem -pubout -out pubkey.pem

See more OpenSSL Examples

How to output the public part of a private key: Demonstrates how to duplicate this OpenSSL command:
openssl pkey -in private.pem -pubout -out pubkey.pem

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
program ChilkatDemo;

// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}

uses
  {$IFDEF UNIX}
  cthreads,
  {$ENDIF}
  SysUtils,
  CkDllLoader,
  Chilkat.PrivateKey,
  Chilkat.PublicKey;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  pkey: TPrivateKey;
  pubKey: TPublicKey;

begin
  success := False;

  pkey := TPrivateKey.Create;

  //  Load the private key from an PEM file:
  success := pkey.LoadPemFile('private.pem');
  if (success = False) then
    begin
      WriteLn(pkey.LastErrorText);
      Exit;
    end;

  pubKey := TPublicKey.Create;
  pkey.ToPublicKey(pubKey);

  success := pubKey.SavePemFile(False,'pubKey.pem');
  if (success <> True) then
    begin
      WriteLn(pubKey.LastErrorText);
      pubKey.Free;
      Exit;
    end;

  WriteLn('Success.');


  pkey.Free;
  pubKey.Free;

end;

// ---------------------------------------------------------------------------

begin

  try
    RunDemo;
  except
    on E: Exception do
      WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
  end;

  WriteLn;
  {$IFDEF MSWINDOWS}
  WriteLn('Press Enter to exit...');
  ReadLn;
  {$ENDIF}
end.