Encrypt & Decrypt entity data in database
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
composer require osw3/symfony-entity-encrypt
Then, enable the bundle by adding it to the list of registered bundles
in the config/bundles.php
file of your project:
// config/bundles.php
return [
// ...
OSW3\EntityEncrypt\EntityEncryptBundle::class => ['all' => true],
];
Edit the configuration file config/packages/entity_encrypt.yaml
entity_encrypt:
algo: aes256
use OSW3\EntityEncrypt\Attribute\Encrypted;
class Message
{
// ...
#[ORM\Column(type: Types::TEXT)]
#[Encrypted] // Just add this Attribute
#[Encrypted(salt: 'my-salt')] // or add this Attribute with salt
private ?string $secret = null;
// ...
}