sodium_crypto_secretbox_keygen

Generate random key for sodium_crypto_secretbox

&reftitle.description; `string` `sodium_crypto_secretbox_keygen`

Generate a key for use with `sodium_crypto_secretbox` and `sodium_crypto_secretbox_open`.

&reftitle.parameters; &no.function.parameters;
&reftitle.returnvalues;

Returns the generated string of cryptographically secure random bytes.

&reftitle.examples;

### `sodium_crypto_secretbox_keygen` example

    <?php
    $key = sodium_crypto_secretbox_keygen();
    var_dump( sodium_bin2hex( $key ) );
    ?>

&example.outputs.similar;

    string(64) "88bd1dc51ec81984f3ddc5a8f59a3d95b647e2da3e879f1b9ceb0abd89e7286c"

### Comparing `sodium_crypto_secretbox_keygen` with `random_bytes`

    <?php
    $key = sodium_crypto_secretbox_keygen();
    $bytes = random_bytes( SODIUM_CRYPTO_SECRETBOX_KEYBYTES );
    var_dump( mb_strlen( $key, '8bit' ) === mb_strlen( $bytes, '8bit' ) );
    ?>

&example.outputs;

    bool(true)

&reftitle.seealso;

- `sodium_bin2hex`
- `random_bytes`