DELPHI sha1 汉字

来源:互联网 发布:java加载不了 编辑:程序博客网 时间:2024/06/06 02:17

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;