WITH#

string Salt = sha1(sha1("Test")); string hash1 = sha1(sha1(INTERFACE.GetUserKey())); string client = sha1(INTERFACE.GetUserKey() + hash1 + Salt); public string sha1(string text) { SHA1CryptoServiceProvider sh = new SHA1CryptoServiceProvider(); sh.ComputeHash(Encoding.UTF8.GetBytes(text)); byte[] re = sh.Hash; StringBuilder sb = new StringBuilder(); foreach (byte b in re) { sb.Append(b.ToString("x2")); } return sb.ToString(); } 

Php

 <?php $Key = "605867360"; $salt = sha1(sha1("Test")); $hash1 = sha1(sha1($Key)); $gen = $Key+$hash1+$salt; echo $server_success = sha1($gen); ?> 

Turns out

  • In C # = 2f08bd86fd4d506a8117de892a8e9df7675aab74
  • In PHP = 75f98970800b3e97f87cb39ee35047700ef22bdc
  • Probably the encodings are different ... - Qwertiy
  • On the file UTF-8 is - Strapon
  • one
    But it’s not something in the file that is considered, but something in memory. Deduce the byte arrays for which you are doing the calculations and check if they are the same. - Qwertiy

1 answer 1

Look, here is the same problem: https://stackoverflow.com/questions/790232/c-sharp-sha-1-vs-php-sha-1-different-results The case is in the encoding: "PHP uses ASCII charset for hash calculations. " You can read the file as UTF8, but before applying hashing, you need to translate it into ASCII: sh.ComputeHash(Encoding.ASCII.GetBytes(text));

  • The joke is that $ salt and $ hash1 coincide with the program, but this is not $ server_success - Strapon
  • Apparently the code in php did not write correctly - Strapon