(Delphi DLL) Example: Crypt2.HashStringENC method
Demonstrates how to call the HashStringENC method.
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Crypt2;
...
procedure TForm1.Button1Click(Sender: TObject);
var
crypt: HCkCrypt2;
s: PWideChar;
hashStr: PWideChar;
begin
crypt := CkCrypt2_Create();
s := 'får';
// The string "får" in utf-8 is composed of these bytes: 0x66 0xC3 0xA5 0x72
CkCrypt2_putCharset(crypt,'utf-8');
CkCrypt2_putEncodingMode(crypt,'hex_lower');
CkCrypt2_putHashAlgorithm(crypt,'sha256');
// Get the hex string for the sha-256 hash of the utf-8 byte representation of the string
hashStr := CkCrypt2__hashStringENC(crypt,s);
Memo1.Lines.Add(hashStr);
// Output:
// cb8f773dd592337ed7f928012a60f48e1efb357beeda124a54461410e216fece
CkCrypt2_Dispose(crypt);
end;
|