PHPackages                             matt9mg/doctrine-encryption-bundle - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. matt9mg/doctrine-encryption-bundle

ActiveSymfony-bundle[Security](/categories/security)

matt9mg/doctrine-encryption-bundle
==================================

Doctrine encryption bundle for Symfony to aid with GDPR and general field encryption

16.8k2PHP

Since Nov 14Pushed 4y ago2 watchersCompare

[ Source](https://github.com/matt9mg/doctrine-encryption-bundle)[ Packagist](https://packagist.org/packages/matt9mg/doctrine-encryption-bundle)[ RSS](/packages/matt9mg-doctrine-encryption-bundle/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

Doctrine Encryption Bundle
==========================

[](#doctrine-encryption-bundle)

[![SensioLabsInsight](https://camo.githubusercontent.com/070f058efe62b06a26515ff7e5e7415d37b1349e49b7a39a7b3e66c24a0f318c/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f35636131616165322d323463612d343866332d396531642d6535363233306433383761632f736d616c6c2e706e67)](https://insight.sensiolabs.com/projects/5ca1aae2-24ca-48f3-9e1d-e56230d387ac)

With GDPR becoming business critical here's a bundle that handles the data encryption layer.

Installation
------------

[](#installation)

`composer require matt9mg/doctrine-encryption-bundle dev-master`

```
   app/AppKernel.php

    public function registerBundles()
    {
        $bundles = [
            ...
            new Matt9mg\Encryption\DoctrineEncryptionBundle(),
            ...
        ];
    }
```

Configuration
-------------

[](#configuration)

***Basic***

Basic configuration will take advantage of the encryption library provided

```
matt9mg_doctrine_encryption:
  key: 'an encryption key'
  iv: 'an encryption iv'
  suffix: 'an encryption suffix'
```

***Full***

```
matt9mg_doctrine_encryption:
  key: 'an encryption key'
  iv: 'an encryption iv'
  suffix: 'an encryption suffix'
  method: 'AES-256-CBC' // This is the default setting
  class: 'Full\Namespace\To\Your\Encryptor' // If not supplied will use the default
```

Usage
-----

[](#usage)

### Using the encryption service in controller

[](#using-the-encryption-service-in-controller)

```
use Matt9mg\Encryption\Bridge\Bridge;

$this->get(Bridge::class)->encrypt($string)
$this->get(Bridge::class)->decrypt($string);
```

### Entity Annotation

[](#entity-annotation)

```
    use Matt9mg\Encryption\Annotation\Encrypted;

    class User {
       /**
       * @Encrypted()
       */
       private $firstname;

    }
```

The above will auto encrypt on `prePersist` and `preUpdate`

### Twig

[](#twig)

```
{{ user.firstname | decrypt }}
```

Design decision
---------------

[](#design-decision)

You'll notice there is no postLoad event to convert back to decrypted. Experience with doctrine is that as the entity is changed it adds it to the queue to be flushed. Say if you have an account with 1000 users each user would be decrypted meaning re saved.

How to add a custom Encryptor
-----------------------------

[](#how-to-add-a-custom-encryptor)

Create a class that extends `Matt9mg\Encryption\Encryptor\EncryptorInterface`. Then register as mentioned in the above config.

Tests
-----

[](#tests)

Yes there a loads of lovely unit tests :)

Roadmap
-------

[](#roadmap)

- Form inputs
- Command line util
- Travis integration

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8473296?v=4)[Matthew Thomas](/maintainers/matt9mg)[@matt9mg](https://github.com/matt9mg)

---

Top Contributors

[![matt9mg](https://avatars.githubusercontent.com/u/8473296?v=4)](https://github.com/matt9mg "matt9mg (37 commits)")

### Embed Badge

![Health badge](/badges/matt9mg-doctrine-encryption-bundle/health.svg)

```
[![Health](https://phpackages.com/badges/matt9mg-doctrine-encryption-bundle/health.svg)](https://phpackages.com/packages/matt9mg-doctrine-encryption-bundle)
```

###  Alternatives

[defuse/php-encryption

Secure PHP Encryption Library

3.9k162.4M214](/packages/defuse-php-encryption)[roave/security-advisories

Prevents installation of composer packages with known security vulnerabilities: no API, simply require it

2.9k97.3M6.4k](/packages/roave-security-advisories)[mews/purifier

Laravel 5/6/7/8/9/10 HtmlPurifier Package

2.0k16.7M113](/packages/mews-purifier)[robrichards/xmlseclibs

A PHP library for XML Security

41278.1M118](/packages/robrichards-xmlseclibs)[bjeavons/zxcvbn-php

Realistic password strength estimation PHP library based on Zxcvbn JS

86917.5M63](/packages/bjeavons-zxcvbn-php)[enlightn/security-checker

A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

33732.2M110](/packages/enlightn-security-checker)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
