#1 2014-05-08 03:48:50

mingda
Member
Registered: 2013-01-04
Posts: 121

crc32 problem when string content has chinese word

in web client, use below link crc32 function in
http://synopse.info/forum/viewtopic.php?pid=9485#p9485

computer such string:

ShipAgent/ShipSpecification?select=*&where=Name like :('%海洋皇后%'): OR ChineseName LIKE :('%海洋皇后%'):

function(str, init)
init is 1725494238,
the result is 450260155

but in delphi test:

procedure TForm5.Button2Click(Sender: TObject);
var
  url: RawUTF8;
  fPrivateSaltHash: Cardinal;
  aTimeStamp, aSignature, fLastTimeStamp: cardinal;
  PTimeStamp: PAnsiChar;
  aURLlength: Integer;
  URISessionSignaturePos: integer;
  s: RawUtf8;
  c,c2: Cardinal;
begin
  url := 'ShipAgent/ShipSpecification?select=*&where=Name like :(''%海洋皇后%''): OR ChineseName LIKE :(''%海洋皇后%''):&session_signature=0051C0FA00D9AABE1AD66CBB';
  URISessionSignaturePos := length(url)-(17+24+1);
  aURLlength := URISessionSignaturePos - 1;
  PTimeStamp := @url[aURLLength+(20+8)]; // P^ points to Hexa8(TimeStamp)

  fPrivateSaltHash := 407090865;
  fLastTimeStamp := 14264847;

  if not HexDisplayToCardinal(PTimeStamp,aTimeStamp) then s := s + 'Error1,';
  if not (aTimeStamp>=fLastTimeStamp) then s := s + 'Error2,';
  if not HexDisplayToCardinal(PTimeStamp+8,aSignature) then s := s + 'Error3,';
//  if not (crc32(crc32(fPrivateSaltHash,PTimeStamp,8),pointer(url),aURLlength)=aSignature) then s := s + 'Error4,';
  c := crc32(fPrivateSaltHash,PTimeStamp,8);
  c2 := crc32(c,pointer(url),aURLlength);
  if not (crc32(c,pointer(url),aURLlength)=aSignature) then s := s + 'Error4,';
  showmessage(inttostr(c2));

end;

the result is 1201321865,
this will cause TAuthSession.IsValidURL return false, then the web client will not pass Auth,
if no chinese word, then two crc32 result is same, which result is right, any help much appreciated, thanks!

Offline

#2 2014-05-08 09:17:51

mingda
Member
Registered: 2013-01-04
Posts: 121

Re: crc32 problem when string content has chinese word

Update, Problem resoved, the javscript crc32 function work on ascii char, so before computer the crc32 value, need first utf8 encode the string, then computer result will same, thanks!

Offline

#3 2014-05-08 13:52:33

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,661
Website

Re: crc32 problem when string content has chinese word

Yes, crc32() is a byte-oriented function, not string-oriented.
smile

Internally, the framework core works with UTF-8 text encoding everywhere (mainly RawUTF8 or memory buffers), not UnicodeString.

Offline

Board footer

Powered by FluxBB