Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Doctrine Encryption Bundle Laravel Package

brandoriented/doctrine-encryption-bundle

View on GitHub
Deep Wiki
Context7

Doctrine Encryption Bundle

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

Installation

composer require brandoriented/doctrine-encryption-bundle dev-master

   app/AppKernel.php
   
   
    public function registerBundles()
    {
        $bundles = [
            ...
            new BrandOriented\Encryption\DoctrineEncryptionBundle(),
            ...
        ];
    }

Configuration

Basic

Basic configuration will take advantage of the encryption library provided

doctrine_encryption:
  key: 'an encryption key'
  iv: 'an encryption iv'
  suffix: 'an encryption suffix'

Full

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

Using the encryption service in controller

use BrandOriented\Encryption\Bridge\Bridge;

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

Entity Annotation

    use BrandOriented\Encryption\Annotation\Encrypted;

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

The above will auto encrypt on prePersist and preUpdate

Twig

{{ user.firstname | decrypt }}

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

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

Tests

Yes there a loads of lovely unit tests :)

Roadmap

  • Form inputs
  • Command line util
  • Travis integration
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity