I'm trying to use Libsodium for the first time to for encryption, but I've encountered an error. I'm running everything on XAMPP; sodium is in the /ext/ folder and I've added extension=sodium
to the php.ini file.
This is my code.
// This refers to the previous code block.
require "safeCrypto.php";
// Do this once then store it somehow:
$key = random_bytes(SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
$message = 'We are all living in a yellow submarine';
$ciphertext = safeEncrypt($message, $key);
$plaintext = safeDecrypt($ciphertext, $key);
echo $ciphertext;
echo $plaintext;
echo phpversion();
It throws this error.
Warning: Use of undefined constant SODIUM_CRYPTO_SECRETBOX_KEYBYTES - assumed 'SODIUM_CRYPTO_SECRETBOX_KEYBYTES' (this will throw an Error in a future version of PHP) in D:\xampp\htdocs\php\crypttest.php on line 6
Fatal error: Uncaught TypeError: random_bytes() expects parameter 1 to be integer, string given in D:\xampp\htdocs\php\crypttest.php:6
get_loaded_extensions()
shows that sodium is NOT installed, and I can't figure out why. The php_sodium.dll file exists in the ext folder and I've added extension=sodium
in the php.ini file.
I'm using PHP 7.2.10.