Lazarus Pascal
Lazarus Pascal
Example: Crypt2.HashStringENC method
Demonstrates how to call the HashStringENC method.Chilkat Lazarus Pascal Downloads
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;
s: string;
hashStr: string;
begin
crypt := TCrypt2.Create;
s := 'får';
// The string "får" in utf-8 is composed of these bytes: 0x66 0xC3 0xA5 0x72
crypt.Charset := 'utf-8';
crypt.EncodingMode := 'hex_lower';
crypt.HashAlgorithm := 'sha256';
// Get the hex string for the sha-256 hash of the utf-8 byte representation of the string
hashStr := crypt.HashStringENC(s);
WriteLn(hashStr);
// Output:
// cb8f773dd592337ed7f928012a60f48e1efb357beeda124a54461410e216fece
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.