Sample code for 30+ languages & platforms
Lazarus Pascal

Example: Crypt2.SetEncodedIV method

Demonstrates how to call the SetEncodedIV 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.Crypt2;

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

procedure RunDemo;
var
  crypt: TCrypt2;

begin
  crypt := TCrypt2.Create;

  crypt.CryptAlgorithm := 'aes';
  crypt.CipherMode := 'cbc';
  crypt.KeyLength := 256;

  //  Note: The lenght of the IV is equal to the block size of the symmetric encryption algorithm.
  //  The block size for AES is 16 bytes.  Therefore, the IV is 16 bytes regardless of the encryption strenght (128-bit, 256-bit, etc.)
  crypt.SetEncodedIV('000102030405060708090A0B0C0D0E0F','hex');

  //  ...
  //  ...


  crypt.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.