### Forum

Forum
﻿
× Components and Libraries for Algorithms Development, discussions, problems and suggestions

# Question Help to understand with TDCP_sha256

• Tigr
• Topic Author
• Offline
• Junior Boarder
1 year 4 weeks ago - 1 year 4 weeks ago #11051 by Tigr
Please explain what's wrong and what's missing!?
Using the component TDCP_sha256 trying to get the string:
0f3aca61475521f3b76d84d86237885fbe30e34f9efe7ddf457aae123b6cdbe0
feeding line:
1b90ee9449c7709cdce4f8e105970aea7eb23d576b636693d4117f9899c42ee9
But in fact display it in the memo is not true! I assume this as the character encoding is different... how to get the correct result?

procedure TForm1.Button1Click(Sender: TObject);
var s,r:string;
begin
S:='1b90ee9449c7709cdce4f8e105970aea7eb23d576b636693d4117f9899c42ee9';
form1.DCP_sha256_1.Init;
form1.DCP_sha256_1.Update(s,64);
SetLength(r, (DCP_sha256_1.HashSize div 8) div SizeOf(Char));
form1.DCP_sha256_1.Final(r[1]);

end;

For earlier grateful!
Last edit: 1 year 4 weeks ago by Tigr.

• Tigr
• Topic Author
• Offline
• Junior Boarder
1 year 4 weeks ago - 1 year 4 weeks ago #11052 by Tigr
Replied by Tigr on topic Help to understand with TDCP_sha256
decided so!

function DigestToStr(Digest: array of byte): string;
var
i: Integer;
begin
Result := '';
for i := 0 to Length(Digest) -1 do
Result := Result + LowerCase(IntToHex(Digest, 2));
end;

function GetStringHash(Source: string): string;
var
Hash: TDCP_sha256;
Digest: array[0..31] of Byte;
begin
Hash := TDCP_sha256.Create(nil);
Hash.Init;
Hash.Final(Digest);
Hash.Free;
Result := DigestToStr(Digest);
end;

procedure TForm1.Button1Click(Sender: TObject);
var s,r:string;
begin
S:='1b90ee9449c7709cdce4f8e105970aea7eb23d576b636693d4117f9899c42ee9';

r:=GetStringHash(s);

end;
Last edit: 1 year 4 weeks ago by Tigr.

• Tigr
• Topic Author
• Offline
• Junior Boarder
1 year 4 weeks ago #11053 by Tigr
Replied by Tigr on topic Help to understand with TDCP_sha256
Question!
How you can implement this method in javascript in the framework described above? where Skey is a hash-256, and text-is a text...

var hash = crypto.createHmac('sha512', Skey).update(text).digest('hex'); // code javaScript