pecl-libsodium-doc
pecl-libsodium-doc copied to clipboard
How to create a secret key for the encrypted cookie recipe
I get this error when trying the encrypted cookie recipe here: https://paragonie.com/book/pecl-libsodium/read/09-recipes.md#encrypted-cookies
Fatal error: Uncaught SodiumException: unsupported key length in /Users/randy/starter/admin/SodiumCookie.php:106
Line 106 is this:
$encKey = sodium_crypto_generichash(
sodium_crypto_generichash('encryption', $cookieName),
$this->key,
SODIUM_CRYPTO_STREAM_KEYBYTES
);
I found this in the ebook but it didn't do the trick
$key = random_bytes(SODIUM_CRYPTO_AUTH_KEYBYTES);
How do I properly generate the secret key that is required?