slam/php-symmetric-encryption

PHP Symmetric Encryption

v1.3.0 2023-11-20 15:17 UTC

This package is auto-updated.

Last update: 2024-06-19 10:20:06 UTC


README

Slam / php-symmetric-encryption

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"