Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Generate Salt in Hex or Base64 Format
See more Encryption Examples
Demonstrates how to generate a cryptographic salt value and get the result as hex or base64.Chilkat Pascal (Lazarus/Delphi) 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.Prng;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
prng: TPrng;
saltHex: string;
saltBase64: string;
begin
// In cryptography, a salt is random data that is used as an additional input to a one-way function that "hashes" data, a password or passphrase.
// Let's say we want to generate a 16-byte salt value..
prng := TPrng.Create;
saltHex := prng.GenRandom(16,'hex');
WriteLn('16-byte salt as hex: ' + saltHex);
saltBase64 := prng.GenRandom(16,'base64');
WriteLn('16-byte salt as base64: ' + saltBase64);
prng.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.