Sample code for 30+ languages & platforms
Lazarus Pascal

Example: Crypt2.SetDecryptCert method

Demonstrates how to call the SetDecryptCert method.

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.BinData,
  Chilkat.Cert,
  Chilkat.Crypt2;

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

procedure RunDemo;
var
  success: Boolean;
  cert: TCert;
  decrypt: TCrypt2;
  bd: TBinData;

begin
  success := False;

  cert := TCert.Create;

  success := cert.LoadPfxFile('c:/pfx_files/my.pfx','password');
  if (success <> True) then
    begin
      WriteLn(cert.LastErrorText);
      Exit;
    end;

  decrypt := TCrypt2.Create;
  decrypt.CryptAlgorithm := 'pki';

  success := decrypt.SetDecryptCert(cert);
  if (success <> True) then
    begin
      WriteLn(decrypt.LastErrorText);
      Exit;
    end;

  bd := TBinData.Create;
  success := bd.LoadFile('c:/someDir/pkcs7_encrypted.dat');

  success := decrypt.DecryptBd(bd);
  if (success <> True) then
    begin
      WriteLn(decrypt.LastErrorText);
      Exit;
    end;

  //  bd contains the decrypted content.


  cert.Free;
  decrypt.Free;
  bd.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.