Base64 encoding or random bin2hex string

When converting "random bytes" to string, is there a difference in whether to use base64_encodeor bin2hex?

$bytes = openssl_random_pseudo_bytes(32); // alternatively read from /dev/urandom

echo base64_encode($bytes); // some 44 character string
echo bin2hex($bytes); // some 64 character string

To use as salt for bcrypt, obviously, a modified base64 is the right choice, because that is what is expected. But for contexts such as an account registration confirmation key or a unique inconsistent object identifier, which is the right choice?

I know random_compatlibrary , but this is also for educational purposes.

+4
source share
1 answer

? , . . .

:

  • Base64 +, / =, URL.

  • Base64 - , , . ( , , A F.)

+4

Source: https://habr.com/ru/post/1608229/


All Articles