I use lockbox3 for years, util now with delphi xe7. Now I'm migrating to Alexandria and facing the problem.
With XE7 I used version 3.4 (or so - I cannot find version number in sources). With Alexandria I use whatever comes from Getit package manager.
My code is like follow.
function TForm1.md5(src: string): string;
function Display(Buf: TBytes): String;
var i: Integer;
begin
Result := '';
for i := 0 to 15 do
Result := Result + Format('%0.2x', [Buf[i]]);
Result := LowerCase(Trim(Result));
end;
var
output : AnsiString;
bytes : TBytes;
P, Sz: integer;
aByte: byte;
s: string;
MyHash : THash;
Lib : TCryptographicLibrary;
begin
Lib := TCryptographicLibrary.Create(nil);
MyHash := THash.Create(nil);
MyHash.CryptoLibrary := Lib;
MyHash.HashId := 'native.hash.MD5';
MyHash.Begin_Hash;
MyHash.HashAnsiString(src);
if not assigned(MyHash.HashOutputValue) then
output := 'nil'
else
begin
SetLength(Bytes, 16);
Sz := MyHash.HashOutputValue.Size;
if Sz <> 16 then
output := Format('wrong size: %d', [Sz])
else
begin
P := 0;
MyHash.HashOutputValue.Position := 0;
while MyHash.HashOutputValue.Read(aByte, 1) = 1 do
begin
bytes[P] := aByte;
Inc(P);
end;
result := Display(Bytes);
end;
end;
MyHash.Destroy;
Lib.Destroy;
end;
This works like a charm in old environment. In Alexandria it throws 'Integer overflow' exception at
MyHash.HashAnsiString(src);
Does any body know, how to solve this problem?
regards M.