DomBlack / php-scrypt

A PHP wrapper fo the scrypt hashing algorithm
Other
209 stars 57 forks source link

Show salt in hex instead of binary #50

Closed Serphentas closed 8 years ago

Serphentas commented 8 years ago

Hi,

I've encountered some issues with the salt being displayed in binary form. To be uniform with other hash functions, I think it would be better to use a hex output.

DomBlack commented 8 years ago

I'm a little confused, do you mean the example generateSalt function or the underlying scrypt function itself?

Both by default return the output in hex, with the scrypt function returning raw binary if you set the last parameter to true:

echo scrypt('testing123', '123', 16384, 8, 1, 32);
// Prints 'ecb460b0448475d3a29ef26fe655fc3a09e6285e4a52f2ecb61bdab075fa1370';
echo scrypt('testing123', '123', 16384, 8, 1, 32, true);
// Prints '�`�D�uӢ��o�U�:    �(^JR���u�p';

And the last line of the generateHash funciton being:

$salt = str_replace(array('+', '$'), array('.', ''), base64_encode($buffer));
Serphentas commented 8 years ago

I was referring to the output of the hash function, when it prints the parameters, the salt and the actual hash. For example: 16$8$1$salt$hash

However the issued I has was related to me using an older version of your wrapper. The new one correctly shows the salt in hex form.

Sorry about the confusion.

DomBlack commented 8 years ago

No problem.