DELPHI sha1 汉字

function sha1(input: string): string;
begin
  with Tidhashsha1.Create do
  try
    Result := HashBytesAsHex(TidBytes(Bytesof(input)));
    
  finally
    free;
  end;
end;

针对 sha1签名,之前没有涉及中文字符,一切正常,加入汉字后,签名错误,需要使用下面方法

function sha1(input: string): string;
begin
  with Tidhashsha1.Create do
  try
    //Result := HashBytesAsHex(TidBytes(Bytesof(input)));
    Result := HashStringAsHex(input,IndyTextEncoding_UTF8);
  finally
    free;
  end;
end;

 

posted on 2024-07-10 15:11  懒猫~  阅读(40)  评论(0)    收藏  举报

导航