paragonie / pecl-libsodium-doc

Free Online Documentation for the Libsodium PHP Extension
https://paragonie.com/book/pecl-libsodium
Creative Commons Attribution 4.0 International
88 stars 11 forks source link

How to create a secret key for the encrypted cookie recipe #18

Open randy-johnson opened 5 years ago

randy-johnson commented 5 years ago

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?