pocketmine\utils\Utils::getRandomBytes PHP Method

getRandomBytes() public static method

This function simply forwards to the PHP random_bytes function.
Deprecation: prefer PHP 7 random_bytes()
public static getRandomBytes ( integer $length = 16, boolean $secure = true, boolean $raw = true, string $startEntropy = "", &$rounds, &$drop ) : string
$length integer default 16, Number of bytes to generate
$secure boolean default true, Generate secure distilled bytes, slower
$raw boolean default true, returns a binary string if true, or an hexadecimal one
$startEntropy string default null, adds more initial entropy
return string
    public static function getRandomBytes($length = 16, $secure = true, $raw = true, $startEntropy = "", &$rounds = 0, &$drop = 0)
    {
        $raw_output = random_bytes($length);
        if ($raw) {
            return $raw_output;
        } else {
            return bin2hex($raw_output);
        }
    }

Usage Example

Example #1
0
 private function networkFunctions()
 {
     $config = new Config(\pocketmine\DATA . "server.properties", Config::PROPERTIES);
     echo "[!] " . $this->lang->query_warning1 . "\n";
     echo "[!] " . $this->lang->query_warning2 . "\n";
     echo "[?] " . $this->lang->query_disable . " (y/N): ";
     if (strtolower($this->getInput("n")) === "y") {
         $config->set("enable-query", false);
     } else {
         $config->set("enable-query", true);
     }
     echo "[*] " . $this->lang->rcon_info . "\n";
     echo "[?] " . $this->lang->rcon_enable . " (y/N): ";
     if (strtolower($this->getInput("n")) === "y") {
         $config->set("enable-rcon", true);
         $password = substr(base64_encode(@Utils::getRandomBytes(20, false)), 3, 10);
         $config->set("rcon.password", $password);
         echo "[*] " . $this->lang->rcon_password . ": " . $password . "\n";
     } else {
         $config->set("enable-rcon", false);
     }
     /*echo "[*] " . $this->lang->usage_info . "\n";
     		echo "[?] " . $this->lang->usage_disable . " (y/N): ";
     		if(strtolower($this->getInput("n")) === "y"){
     			$config->set("send-usage", false);
     		}else{
     			$config->set("send-usage", true);
     		}*/
     $config->save();
     echo "[*] " . $this->lang->ip_get . "\n";
     $externalIP = Utils::getIP();
     $internalIP = gethostbyname(trim(`hostname`));
     echo "[!] " . $this->lang->get("ip_warning", ["{{EXTERNAL_IP}}", "{{INTERNAL_IP}}"], [$externalIP, $internalIP]) . "\n";
     echo "[!] " . $this->lang->ip_confirm;
     $this->getInput();
 }
All Usage Examples Of pocketmine\utils\Utils::getRandomBytes