You need Symfony 2.7+ with PcdxParameterEncryptionBundle already installed and enabled (please refer to its own documentation).
Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:
$ composer require picodexter/parameter-encryption-defuse-bundle "~1"
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Then, enable the bundle by adding it to the list of registered bundles
in the app/AppKernel.php
file of your project:
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Picodexter\ParameterEncryptionDefuseBundle\PcdxParameterEncryptionDefuseBundle(),
);
// ...
}
// ...
}
You can now use the following services in the PcdxParameterEncryptionBundle
configuration:
- Encrypter:
pcdx_parameter_encryption_defuse.encryption.encrypter.defuse_php_encryption
- Decrypter:
pcdx_parameter_encryption_defuse.encryption.decrypter.defuse_php_encryption
Example:
Application configuration:
.. configuration-block:: .. code-block:: yaml # app/config/config.yml pcdx_parameter_encryption: algorithms: - id: 'defuse' pattern: type: 'value_prefix' arguments: - '=#!PPE!defuse!#=' encryption: service: 'pcdx_parameter_encryption_defuse.encryption.encrypter.defuse_php_encryption' key: '%parameter_encryption.defuse.key%' decryption: service: 'pcdx_parameter_encryption_defuse.encryption.decrypter.defuse_php_encryption' key: '%parameter_encryption.defuse.key%' .. code-block:: xml <!-- app/config/config.xml --> <?xml version="1.0" encoding="UTF-8" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ppe="https://picodexter.io/schema/dic/pcdx_parameter_encryption" xsi:schemaLocation="https://picodexter.io/schema/dic/pcdx_parameter_encryption https://picodexter.io/schema/dic/pcdx_parameter_encryption/pcdx_parameter_encryption-1.0.xsd"> <ppe:config> <ppe:algorithm id="defuse"> <ppe:pattern type="value_prefix"> <ppe:argument>=#!PPE!defuse!#=</ppe:argument> </ppe:pattern> <ppe:encryption service="pcdx_parameter_encryption_defuse.encryption.encrypter.defuse_php_encryption"> <ppe:key>%parameter_encryption.defuse.key%</ppe:key> </ppe:encryption> <ppe:decryption service="pcdx_parameter_encryption_defuse.encryption.decrypter.defuse_php_encryption"> <ppe:key>%parameter_encryption.defuse.key%</ppe:key> </ppe:decryption> </ppe:algorithm> </ppe:config> </container> .. code-block:: php // app/config/config.php $container->loadFromExtension( 'pcdx_parameter_encryption', [ 'algorithms' => [ [ 'id' => 'defuse', 'pattern' => [ 'type' => 'value_prefix', 'arguments' => ['=#!PPE!defuse!#='], ], 'encryption' => [ 'service' => 'pcdx_parameter_encryption_defuse.encryption.encrypter.defuse_php_encryption', 'key' => '%parameter_encryption.defuse.key%', ], 'decryption' => [ 'service' => 'pcdx_parameter_encryption_defuse.encryption.decrypter.defuse_php_encryption', 'key' => '%parameter_encryption.defuse.key%', ], ], ], ] );
Parameters:
.. configuration-block:: .. code-block:: yaml # app/config/parameters.yml parameters: parameter_encryption.defuse.key: 'YOUR_ENCRYPTION_KEY' .. code-block:: xml <!-- app/config/parameters.xml --> <?xml version="1.0" encoding="UTF-8" ?> <container xmlns="http://symfony.com/schema/dic/services" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> <parameters> <parameter key="parameter_encryption.defuse.key">YOUR_ENCRYPTION_KEY</parameter> </parameters> </container> .. code-block:: php // app/config/parameters.php $container->setParameter('parameter_encryption.defuse.key', 'YOUR_ENCRYPTION_KEY');
You can generate a random encryption key by using
defuse/php-encryption
's CLI tool:$ ./vendor/bin/generate-defuse-key