0

I tried this:

C#

Convert.ToBase64String(
    MD5.Create().ComputeHash(
        Encoding.Default.GetBytes($"SALTstring{PasswordBox.Text}")
    )
);

PHP

$salt = "SALTstring";
$pass = "password";
$suma = $salt . $pass;
*$final = unpack("H*",$suma);*
$junto = implode($final);
$hashed = hash('md5', $junto);
echo $tu = base64_encode($hashed);

The result is different in the procedures

EDIT

There were some tweaks:

C string:

$final = unpack("H*",$suma); >>> $final = unpack("a*",$suma); 

Md5 Raw bytes

$hashed = hash('md5', $junto); >>> echo base64_encode(md5($junto, true)) 
Caconde
  • 4,177
  • 7
  • 35
  • 32
Tievo
  • 1
  • 1
  • 1
    Your problem is almost definitely that `Encoding.Default` isn't [doing what you might expect it to be doing](https://stackoverflow.com/a/6006451/231316). – Chris Haas Nov 16 '20 at 16:32
  • @ChrisHaas thanks for the answer, the problem is c# procedure is active in a program and can not change – Tievo Nov 16 '20 at 17:00
  • For each installation (hopefully you have just one), you'll need to inspect what the default encoding's [CodePage](https://learn.microsoft.com/en-us/dotnet/api/system.text.encoding.codepage?view=net-5.0#System_Text_Encoding_CodePage) is, and then reproduce a string to byte array in PHP, [`mb_convert_encoding`](https://www.php.net/manual/en/function.mb-convert-encoding.php) should help. During this process, ignore hashing for now, only focus on creating the same byte array from both systems. – Chris Haas Nov 16 '20 at 17:34
  • Currently the problem is not in the byte array it is in the md5 hash, the byte array are the same – Tievo Nov 16 '20 at 18:24

0 Answers0