Xor-el / HashLib4Pascal

Hashing for Modern Object Pascal
MIT License
220 stars 80 forks source link

Example needed #12

Closed boxi78 closed 4 years ago

boxi78 commented 4 years ago

Hi!

I want a simple thing: to encode a string SHA3-512. Can you help me? Which unit, whose function knows this? Thanks in advance!

Xor-el commented 4 years ago
uses
SysUtils,
HlpHashFactory;
.....
var
HashResult: String;
begin
HashResult := THashFactory.TCrypto.CreateSHA3_512().ComputeString('My String', TEncoding.UTF8).ToString();
end;

The unit tests has a lot of example code, you can take some time to look at it.

boxi78 commented 4 years ago

Thanks! This was fast! It works. Can't encode a string longer than 255?

Xor-el commented 4 years ago

Can't encode a string longer than 255?

who says you can't?

uses
  SysUtils,
  HlpHashFactory;
.....
var
  I: Int32;
  Input, HashResult: string;
begin
  Input := '';
  for I := 0 to 10000 do
  begin
    Input := Input + 'A';
  end;
  HashResult := THashFactory.TCrypto.CreateSHA3_512().ComputeString(
    Input, TEncoding.UTF8).ToString();
end;
boxi78 commented 4 years ago

Then what can I do? For the following code:

` procedure TForm1.Button1Click(Sender: TObject); var HashResult: String; sSzoveg : string; begin sSzoveg := 'TSTKFT122256420171230182545ce-8f5e-215119fa7dd621DLMRHRLH2S4317798460962869BC67F07C48EA7E4A3AFA301513CEB87B8EB94ECF92BC220A89C480F87F0860E85E29A3B6C0463D4F29712C5AD48104A6486CE839DC2F24CBA881218238933F6FFB9E167445CB4DAA9749BCF484FDE48AB7649FD25E8B634A4736A65A7C4A8E2831119F739837E006566F97370415AAD55E268605206F2A6C';

HashResult := THashFactory.TCrypto.CreateSHA3_512().ComputeString(sSzoveg, TEncoding.UTF8).ToString(); Memo2.Text := HashResult; end; `

I get this error: [dcc32 Error] Unit1.pas(51): E2056 String literals may have at most 255 elements

boxi78 commented 4 years ago

Sorry! I was stupid. That was a basic Delphi thing.

boxi78 commented 4 years ago

Everything works, thanks again for your help!