slam/php-symmetric-encryption

PHP Symmetric Encryption

v1.4.0 2024-09-25 07:16 UTC

This package is auto-updated.

Last update: 2024-11-14 20:10:52 UTC


README

Latest Stable Version Downloads Integrate Code Coverage Infection MSI

V1: encrypt strings with sodium_crypto_aead_xchacha20poly1305_ietf_encrypt function.

Installation

To install with composer run the following command:

$ composer require slam/php-symmetric-encryption

Usage

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"