1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
uses DCPsha256,
 
function DigestToStr(Digest: array of byte): string;
var
  i: Integer;
begin
  Result := '';
  for i := 0 to Length(Digest) - 1 do
    Result := Result + uppercase(IntToHex(Digest[i], 2));
end;
 
function GetStringHash(Source: AnsiString): string;
var
  Hash: TDCP_sha256;
  Digest: array[0..31] of byte;
begin
  Hash := TDCP_sha256.Create(nil);
  Hash.Init;
  Hash.UpdateStr(Source);
  Hash.Final(Digest);
  Hash.Free;
  Result := DigestToStr(Digest);
end;