V1: encrypt strings with sodium_crypto_aead_xchacha20poly1305_ietf_encrypt
function.
To install with composer run the following command:
$ composer require slam/php-symmetric-encryption
use SlamSymmetricEncryption\V1Encryptor;
// Generate a key and save it somewhere
$key = V1Encryptor::generateKey();
var_dump($key); // string(44) "Hog2u9jtOzyt+mPyAJwp8v3dI6Uvp1T4FUKrAjizVGo="
// Use the key
$encryptor = new V1Encryptor($key);
$ciphertext = $encryptor->encrypt('foo');
var_dump($ciphertext); // string(59) "dznmjbqHnI_26crKpRYvp125K9N6ctqU0kVCmoSRbG7HAKCIrnAz0RBELQ"
$plaintext = $encryptor->decrypt($ciphertext);
var_dump($plaintext); // string(3) "foo"