Sample code for 30+ languages & platforms
Lazarus Pascal

Example: Crypt2.EncryptSb method

Demonstrates how to call the EncryptSb 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.StringBuilder,
  Chilkat.Crypt2;

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

procedure RunDemo;
var
  success: Boolean;
  crypt: TCrypt2;
  bdEncrypted: TBinData;
  sbPlainText: TStringBuilder;

begin
  success := False;

  crypt := TCrypt2.Create;

  bdEncrypted := TBinData.Create;
  sbPlainText := TStringBuilder.Create;

  sbPlainText.Append('Text to be encrypted');

  //  ...
  //  Set the secret key ...
  //  Set properties such as CryptAlgorithm, CipherMode, PaddingScheme, KeyLength
  //  Set the IV if needed ...
  //  ...

  crypt.Charset := 'utf-8';

  success := crypt.EncryptSb(sbPlainText,bdEncrypted);
  if (success = False) then
    begin
      WriteLn(crypt.LastErrorText);
      Exit;
    end;


  crypt.Free;
  bdEncrypted.Free;
  sbPlainText.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.