https://github.com/slamdunk/php-symmetric-encryption
PHP Symmetric Encryption
https://github.com/slamdunk/php-symmetric-encryption
Last synced: 8 months ago
JSON representation
PHP Symmetric Encryption
- Host: GitHub
- URL: https://github.com/slamdunk/php-symmetric-encryption
- Owner: Slamdunk
- License: mit
- Created: 2021-10-29T09:56:50.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-10-30T03:10:30.000Z (over 1 year ago)
- Last Synced: 2024-10-30T06:14:27.240Z (over 1 year ago)
- Language: PHP
- Homepage:
- Size: 125 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Slam / php-symmetric-encryption
[](https://packagist.org/packages/slam/php-symmetric-encryption)
[](https://packagist.org/packages/slam/php-symmetric-encryption)
[](https://github.com/Slamdunk/php-symmetric-encryption/actions)
[](https://codecov.io/gh/Slamdunk/php-symmetric-encryption?branch=master)
[](https://dashboard.stryker-mutator.io/reports/github.com/Slamdunk/php-symmetric-encryption/master)
V1: encrypt strings with [`sodium_crypto_aead_xchacha20poly1305_ietf_encrypt`](https://www.php.net/manual/en/function.sodium-crypto-aead-xchacha20poly1305-ietf-encrypt.php) function.
## Installation
To install with composer run the following command:
```console
$ composer require slam/php-symmetric-encryption
```
## Usage
```php
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"
```