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;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章