Delphi Hash算法[4] SHA1

Delphi Hash算法[4] SHA1

引用单元:IdHashSHA

HashtoHex(const aHash:TidBytes):string;override;
HashBytesAsHex(const aHash:TidBytes):string;  //该方法将TidBytes类型返回string类;
HashStringAsHex(const AStr:String;ADestEncoding:TidTextEncoding=nil):string  //常规SHA1(utf-8)加密:40位SHA1大写

1、正常输出

uses IdHashSHA, IdGlobal;

function SHA1(Str: string): string;
begin
  with TIdHashSHA1.Create do
  try
    Result := LowerCase(HashBytesAsHex(TidBytes(Bytesof(Str))));  
  finally
    Free;
  end;
end;

2、UTF-8 格式输出

function sha1(Str: string): string;
begin
  with Tidhashsha1.Create do
  try
    Result := HashStringAsHex(Str,IndyTextEncoding_UTF8);
  finally
    free;
  end;
end;

  

 

 

创建时间:2021.04.29  更新时间:

posted on 2021-04-29 15:13  滔Roy  阅读(895)  评论(0编辑  收藏  举报

导航