gwsn / php-encrypt
Simple helpers for encrypt and decrypt content
Installs: 14 608
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- ext-sodium: *
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-04 14:24:12 UTC
README
Simple tooling to encrypt and decrypt content
Installation
You can install the package via composer:
composer require gwsn/php-encrypt
Plain Usage
use GWSN/Encrypt/Encryptor; $encryptor = new Encryptor('secretKey'); $encrypted = $encryptor->encrypt('content'); $decrypted = $encryptor->decrypt($encrypted);
Use in Symfony
Add the following part to the config/services.yaml
- Where the kernel.secret should be set and a valid string of 32 characters, alternative you can set a random secret key
GWSN\Encrypt\Encryptor: arguments: $secretKey: '%kernel.secret%'
And you can use it in any function with dependency injection
private Encryptor $encryptor; public function __construct(Encryptor $encryptor) { $this->encryptor = $encryptor; } public function makeItSecret(string $content): string { return $this->encryptor->encrypt($content); } public function makeItReadable(string $content): string { return $this->encryptor->decrypt($content); }
Test
composer run test