Encrypt XOR in Delphi / Decrypt in PHP -


ok guys, few days ago translated simple xor function in delphi php , working fine. today when tried again unknown reason, it's broken. i'm doing is: first base64 encode in string, xor it. send php on post method, , in php 'unxor' , decode base64. function in delphi(i'm using encodebase64 encddecd unit):

function encryptstr(input: ansistring; seed: integer): ansistring; var : integer; output : ansistring; begin     input:= encodebase64(bytesof(utf8encode(input)),  length(bytesof(utf8encode(input))));     output := '';     := 1 length(input)         output := output + ansichar(ord(input[i]) xor (seed));     result:= output; end; 

ok, send way on indy http(don't know if matters, can useful)

procedure tform1.dopost; var   http: tidhttp;   lpost: tstringlist; begin   http:= tidhttp.create(nil);   lpost:= tstringlist.create;   http.request.useragent:='mozilla/5.0 (compatible; msie 10.0; windows nt 6.1; trident/6.0)';   lpost.add('pname=' + encryptstr('test.exe', 232));   lpost.add('bytetype=' + encryptstr('unicode', 232));   http.post('http://192.168.1.12/panel.php?uid=09ed-erty-as98-1498', lpost); 

in php receive/decrypt in way:

 function decryptstr($str)   {     $key = '232'; //key need same hook using!     $strsize = @strlen($str);        $j = @strlen($key);     for($i=$strsize-1; $i >= 0; $i--)      {        $str[$i] = @chr(@ord($str[$i]) ^ $key);      }      $str = base64_decode($str);      return $str;     }   if(isset($_post['pname']) && isset($_post['bytetype']) && ($_post['bytetype'] != ''))   {     saveinfo($uid, decryptstr($_post['pname']), decryptstr($_post['bytetype']), $con);    } 

the saveinfo function doing echo in variables decrypted, corrupted... what's wrong?

the problem utf8 encoding. changed first xor after xor base64. , in base64 in delphi did:

input:= encodebase64(bytesof(input), length(bytesof(input)));

instead of:

input:= encodebase64(bytesof(utf8encode(input)), length(bytesof(utf8encode(input))));

removing utf8encode correctly decrypted in php.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

IIS->Tomcat Redirect: multiple worker with default -