The goal is the create a library which is modular, fast and portable. There is no platform-specific code, no Assembly, no includes, no conditinal defines. Every algorith has it's own separate file and if you need just one algorithm in your program you can just copy 2 files- the file with the algorithm you need and "HasherBase.pas". Optionally you can copy "Hasher.pas" but that's just a helper class.
More soon...
https://github.com/PascalVault/PHP_Hashing
hashing a String
uses Hasher;
var Hasher: THasher;
Hash: String;
begin
try
Hasher := THasher.Create('CRC-32 JAMCRC');
Hasher.Update('123456789');
Hash := Hasher.Final;
Hasher.Free;
Memo1.Lines.Add( Hash );
finally
end;
hashing a Stream
uses Hasher;
var Hasher: THasher;
Hash: String;
Msg: TMemoryStream;
begin
try
Msg := TMemoryStream.Create;
Hasher := THasher.Create('CRC-32 JAMCRC');
Hasher.Update(Msg);
Hash := Hasher.Final;
Hasher.Free;
Memo1.Lines.Add( Hash );
finally
Msg.Free;
end;
hashing a file
uses Hasher;
var Hasher: THasher;
Hash: String;
begin
try
Hasher := THasher.Create('CRC-32 JAMCRC');
Hasher.UpdateFile('directory/file.exe');
Hash := Hasher.Final;
Hasher.Free;
Memo1.Lines.Add( Hash );
finally
end;
hashing a String
uses CRC64;
var Hasher: THasherCRC64;
Hash: String;
Msg: String;
begin
Msg := '123456789';
Hasher := THasherCRC64.Create;
Hasher.Update(@Msg[1], Length(Msg));
Hash := Hasher.Final;
Hasher.Free;
Memo1.Lines.Add( Hash );
end;
hashing an Array
uses CRC64;
var Hasher: THasherCRC64;
Hash: String;
Msg: array of Byte;
Len: Integer;
begin
SetLength(Msg, Len);
Hasher := THasherCRC64.Create;
Hasher.Update(@Msg[0], Len);
Hash := Hasher.Final;
Hasher.Free;
Memo1.Lines.Add( Hash );
end;