4
將「隨機字節」轉換爲字符串時,我應該使用base64_encode
還是bin2hex
有什麼區別?Base64編碼或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
要用作鹽bcrypt
,顯然修改base64是正確的選擇,因爲這是預期的。但是對於諸如帳戶註冊確認密鑰或唯一的非順序對象標識符這樣的上下文,這是正確的選擇?
我知道random_compat
library,但這也是爲了學習的目的。