2024 年 PHP Conference Japan

Random\Engine\Secure::generate

(PHP 8 >= 8.2.0)

Random\Engine\Secure::generate產生加密安全的隨機性

說明

public Random\Engine\Secure::generate(): 字串

回傳加密安全的隨機性。

隨機性來源的優先順序如下:

  • Linux:» getrandom()/dev/urandom

  • FreeBSD >= 12 (PHP >= 7.3):» getrandom()/dev/urandom

  • Windows (PHP >= 7.2):» CNG-API

    Windows:» CryptGenRandom

  • macOS (PHP >= 8.2; >= 8.1.9; >= 8.0.22 如果 CCRandomGenerateBytes 在編譯時可用): CCRandomGenerateBytes()

    macOS (PHP >= 8.1; >= 8.0.2): arc4random_buf(), /dev/urandom

  • NetBSD 7 以上版本 (PHP 7.1 以上;7.0.1 以上):arc4random_buf(),/dev/urandom

  • OpenBSD 5.5 以上版本 (PHP 7.1 以上;7.0.1 以上):arc4random_buf(),/dev/urandom

  • DragonflyBSD (PHP 8.1 以上):» getrandom()/dev/urandom

  • Solaris (PHP 8.1 以上):» getrandom()/dev/urandom

  • 任何未提及之作業系統與 PHP 版本組合:/dev/urandom
  • 如果上述所有來源皆無法使用或產生亂數,則會拋出 Random\RandomException 例外。

參數

此函式無參數。

回傳值

一個包含 PHP_INT_SIZE 個加密強度安全的隨機位元組之字串。

錯誤/例外

新增註解

使用者貢獻的註解

此頁面沒有使用者貢獻的註解。
To Top