Sample code for 30+ languages & platforms
Lazarus Pascal Requires Chilkat v11.8.0+

Add a PEM Source of Certificates for Chain Building

See more PFX/P12 Examples

Demonstrates Pfx.AddPemSource, which adds the certificates of a Pem object to the set of certificate sources available for chain building.

The file path is relative to the application's current working directory. An absolute path may also be used. Supply the path appropriate to your own environment.

Background. The call takes the certificates the Pem object has at the time of the call. Providing extra intermediate certificates lets Chilkat complete the chains of the certificates of a PFX. The added certificates are a lookup source only: they do not become part of the PFX. AddPemSource can be called multiple times. Each call adds more certificates to the ones already added. AddPemSource was added in Chilkat v11.8.0 and replaces UseCertVault.

Chilkat Lazarus Pascal Downloads

Lazarus Pascal
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.Pfx,
  Chilkat.Cert,
  Chilkat.Pem;

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

procedure RunDemo;
var
  success: Boolean;
  pfx: TPfx;
  caCert: TCert;
  pem: TPem;

begin
  success := False;

  pfx := TPfx.Create;

  //  The file path is relative to the application's current working directory.  An absolute path
  //  may also be used.  Supply the path appropriate to your own environment.
  //  Load an additional certificate (such as an intermediate CA certificate), and add it to a Pem object.
  caCert := TCert.Create;
  success := caCert.LoadFromFile('qa_data/intermediate_ca.cer');
  if (success = False) then
    begin
      WriteLn(caCert.LastErrorText);
      Exit;
    end;

  pem := TPem.Create;
  success := pem.AddCert(caCert,False);
  if (success = False) then
    begin
      WriteLn(pem.LastErrorText);
      Exit;
    end;

  //  Make the certificates of the Pem object available as sources for chain building.  The call takes
  //  the certificates the Pem object has at this moment.  AddPemSource can be called multiple times.
  //  Each call adds more certificates to the ones already added.
  success := pfx.AddPemSource(pem);
  if (success = False) then
    begin
      WriteLn(pfx.LastErrorText);
      Exit;
    end;
  WriteLn('The certificates of the PEM object were added as a chain-building source.');


  pfx.Free;
  caCert.Free;
  pem.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.