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 更新时间:
博客园 滔Roy https://www.cnblogs.com/guorongtao 希望内容对你有所帮助,谢谢!