system.hash.pas


system.hash.pas

delphi xe8開始提供system.hash.pas。

xe10.4.1版本,提供有幾個記錄:

THash = record

THashBobJenkins = record

THashMD5 = record

THashSHA1 = record

THashSHA2 = record

uses  System.Hash;

function md5_hmac(const val, key: string): string;
begin
  var md5: THashMD5 := THashMD5.Create;
  Result := md5.GetHMAC(val, key);
end;

function md5_utf8(const val: string): string;
begin
  var md5: THashMD5 := THashMD5.Create;
  md5.Update(TEncoding.UTF8.GetBytes(val));
  Result := md5.HashAsString;
end;

function sha1_utf8(const val: string): string;
begin
  var sha1: THashSHA1 := THashSHA1.Create;
  sha1.Update(TEncoding.UTF8.GetBytes(val));
  Result := sha1.HashAsString;
end;

function sha2_utf8(const val: string): string;
begin
  var sha2: THashSHA2 := THashSHA2.Create;
  sha2.Update(TEncoding.UTF8.GetBytes(val));
  Result := sha2.HashAsString;
end;

procedure TForm2.Button1Click(Sender: TObject);
begin
  Memo1.Lines.Add(md5_utf8('詠南中間件'));         //ce33960c8f97c85161a8b28b7000b3c6
  Memo1.Lines.Add(sha1_utf8('詠南中間件'));        //2566ca7678fcdb309846eabef3911dc6e5f8814d
  Memo1.Lines.Add(sha2_utf8('詠南中間件'));        //f3bbbfaf81071d67f02fd519553789c671c7e0514045885e5bd8faa80d66792f
  Memo1.Lines.Add(md5_hmac('詠南中間件', '鑰匙')); //0796b66fa3180024cb5e49cba66dbf58
end;

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM