Simple tooling to encrypt and decrypt content
You can install the package via composer:
composer require gwsn/php-encrypt
use GWSN/Encrypt/Encryptor;
$encryptor = new Encryptor('secretKey');
$encrypted = $encryptor->encrypt('content');
$decrypted = $encryptor->decrypt($encrypted);
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);
}
composer run test