protected static function openssl_random_pseudo_bytes_exists()
 {
     if (!isset(self::$openssl_random_pseudo_bytes_exists)) {
         self::$openssl_random_pseudo_bytes_exists = function_exists('openssl_random_pseudo_bytes') && (version_compare(PHP_VERSION, '5.3.4') >= 0 || !self::is_windows());
     }
     return self::$openssl_random_pseudo_bytes_exists;
 }
Beispiel #2
0
 protected static function random_pseudo_bytes($length)
 {
     if (!isset(self::$openssl_random_pseudo_bytes_exists)) {
         self::$openssl_random_pseudo_bytes_exists = function_exists('openssl_random_pseudo_bytes');
     }
     if (self::$openssl_random_pseudo_bytes_exists) {
         return openssl_random_pseudo_bytes($length);
     }
     // Borrowed from http://phpseclib.com/
     $rnd = '';
     for ($i = 0; $i < $length; $i++) {
         $sha = hash('sha256', mt_rand());
         $char = mt_rand(0, 30);
         $rnd .= chr(hexdec($sha[$char] . $sha[$char + 1]));
     }
     return $rnd;
 }