lundi 22 octobre 2018

What is the most efficient way to create randomness in PHP

So i was thinking about that what is the most efficient way to create randomness in PHP. I want to create key that is generated randomly by PHP. Now i have been testing few functions example random_bytes() combined with bin2hex() but i'm not sure if those functions are the most efficient ones. I don't doubt security of these functions, but i want to hear other possible choices from you guys. Friend of mine suggested me library named "libsodium".

I'm not sure that is this any professional way to program, but the way i implement some randomness to create my key right now is this:

$bytes = bin2hex(random_bytes(32));
$time = strval(time());
$bytes = str_shuffle($bytes . $time);
$random_str = hash('sha256', $bytes);

I hope i get some constructive feedback from you guys. Thank you!




Aucun commentaire:

Enregistrer un commentaire