Document how to generate a string of random bytes

Signed-off-by: Maurício Meneghini Fauth <mauricio@fauth.dev>
This commit is contained in:
Maurício Meneghini Fauth 2022-09-15 18:41:32 -03:00
parent 700db7e72b
commit 69bc866773
No known key found for this signature in database
GPG Key ID: 6A16FD38AFC89CC8
3 changed files with 36 additions and 1 deletions

View File

@ -11,7 +11,7 @@ declare(strict_types=1);
/**
* This is needed for cookie based authentication to encrypt the cookie.
* Needs to be a 32-bytes long string of random bytes.
* Needs to be a 32-bytes long string of random bytes. See FAQ 2.10.
*/
$cfg['blowfish_secret'] = ''; /* YOU MUST FILL IN THIS FOR COOKIE AUTH! */

View File

@ -1888,6 +1888,8 @@ Generic settings
A secret key used to encrypt/decrypt the URL query string.
Should be 32 bytes long.
.. seealso:: :ref:`faq2_10`
Cookie authentication options
-----------------------------
@ -1933,6 +1935,8 @@ Cookie authentication options
`sodium\_crypto\_secretbox\_open <https://www.php.net/sodium_crypto_secretbox_open>`_ PHP functions to encrypt
and decrypt cookies, respectively.
.. seealso:: :ref:`faq2_10`
.. config:option:: $cfg['CookieSameSite']
:type: string

View File

@ -867,6 +867,37 @@ If using PHP 5.4.0 or higher, you must set
starting from phpMyAdmin version 4.0.4, session-based upload progress has
been temporarily deactivated due to its problematic behavior.
.. _faq2_10:
2.10 How to generate a string of random bytes
---------------------------------------------
One way to generate a string of random bytes suitable for cryptographic use is using the
`random_bytes <https://www.php.net/random_bytes>`_ :term:`PHP` function. Since this function returns a binary string,
the returned value should be converted to printable format before being able to copy it.
For example, the :config:option:`$cfg['blowfish_secret']` configuration directive requires a 32-bytes long string. The
following command can be used to generate a hexadecimal representation of this string.
.. code-block:: sh
php -r 'echo bin2hex(random_bytes(32)) . PHP_EOL;'
The above example will output something similar to:
.. code-block:: sh
f16ce59f45714194371b48fe362072dc3b019da7861558cd4ad29e4d6fb13851
And then this hexadecimal value can be used in the configuration file.
.. code-block:: php
$cfg['blowfish_secret'] = sodium_hex2bin('f16ce59f45714194371b48fe362072dc3b019da7861558cd4ad29e4d6fb13851');
The `sodium_hex2bin <https://www.php.net/sodium_hex2bin>`_ is used here to convert the hexadecimal value back to the
binary format.
.. _faqlimitations:
Known limitations