More then 7 characters and encyption's dont match C# and PHP -


i have password hashing method in c# i'm trying port php website, allow both website , application use passwords same database (application requires website account use). problem is, once password gets on 7 characters in length, result different in php i'm getting in c#, password less 8 characters, matches c# encryption exactly.

here method in c#

    public static byte[] passencode(byte[] pass)     {         int = 0;         int num = 0x79707367; // starting num         (int = 0; < pass.length; i++)         {             num = passlame(num);             = num % 0xff;             pass[i] ^= (byte)a;         }          return pass;     }      private static int passlame(int num)     {         int c = (num >> 16) & 0xffff;         int = num & 0xffff;          c *= 0x41a7;         *= 0x41a7;         += ((c & 0x7fff) << 16);          if (a < 0)         {             &= 0x7fffffff;             a++;         }          += (c >> 15);          if (a < 0)         {             &= 0x7fffffff;             a++;         }          return a;     } 

and methods in php:

    function passencode($pass)     {         $a = 0;         $num = 0x79707367;         ($i = 0; $i < sizeof($pass); $i++)         {             $num = passlame($num);             $a = $num % 0xff;             $pass[$i] ^= $a;         }          return $pass;     }      function  passlame($num)     {         $c = ($num >> 16) & 0xffff;         $a = $num & 0xffff;          $c *= 0x41a7;         $a *= 0x41a7;         $a += (($c & 0x7fff) << 16);          if ($a < 0)         {             $a &= 0x7fffffff;             $a++;         }          $a += ($c >> 15);          if ($a < 0)         {             $a &= 0x7fffffff;             $a++;         }          return $a;     } 

the bytes i'm using word "testing".

bytes = ([0]=> 116 [1]=> 101 [2]=> 115 [3]=> 116 [4]=> 105 [5]=> 110 [6]=> 103) 

when plug these in, 8th digit returned (and beyond if using larger pass) lot different in c#./ results

c#:

[0]=> int(98) [1]=> int(151) [2]=> int(135) [3]=> int(134) [4]=> int(66) [5]=> int(181) [6]=> int(113) 

php:

[0]=> int(98) [1]=> int(151) [2]=> int(135) [3]=> int(134) [4]=> int(66) [5]=> int(181) [6]=> int(11) 

can me solve this? i'm using 32bit webserver , compiling application in 32bit well.

i believe php handles integer overflow converting value float. cause of problem.

you write custom functions arithmetic check overflow , mimic c#'s wraparound behavior.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -