0

I'm hashing using sha256 and outputting it in binary, and storing it in Mysql's BINARY(32).

 echo $testsha256 = hash( 'sha256', "aKyAmNsb", true );

However, when I retrieve this value from the database, it's Different

 print_r(str_split($returnedpassword));
 echo "<br>";
 print_r(str_split($testsha256));
 echo "<br>";

Array ( [0] => ú [1] => È [2] => c [3] => [4] => u [5] => k [6] => ë [7] => a [8] => Ð [9] => ‰ [10] => V [11] => û [12] => E [13] => [ [14] => [15] => Ø [16] => Ý [17] => Q [18] => â [19] => ž [20] => ? [21] => [22] => ¾ [23] => ¨ [24] => ÷ [25] => 9 [26] => í [27] => Ž [28] => [29] => 5 [30] => ˆ [31] => )

Array ( [0] => ú [1] => È [2] => c [3] => [4] => u [5] => k [6] => ë [7] => \ [8] => a [9] => Ð [10] => ‰ [11] => V [12] => û [13] => E [14] => [ [15] => [16] => Ø [17] => Ý [18] => Q [19] => â [20] => ž [21] => ? [22] => [23] => ¾ [24] => ¨ [25] => ÷ [26] => 9 [27] => í [28] => Ž [29] => [30] => 5 [31] => ˆ )

As you can see, the binary returned from Mysql is missing a '\' before 'a' on index 8. Index 8 should hold '\', as it does in the $testsha256, but the '\' is not there in the $returnedresult

2
  • How are you inserting the data? Can you post your PHP code for the insert? Commented Mar 6, 2010 at 19:23
  • Sounds like either something in your toolchain has clobbered some control characters, or perhaps some unwanted encoding conversion has occurred. What language are you using ? What actually got into the database ("select hex( value ) from table" ) ? Commented Mar 6, 2010 at 19:26

1 Answer 1

1

Use mysql_real_escape_string when inserting the hash into the database.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.