brandoriented / doctrine-encryption-bundle
Doctrine加密包,用于帮助Symfony处理GDPR和通用字段加密
1.1.1
2018-05-23 09:02 UTC
Requires
- php: >=7
- doctrine/common: 2.*
- doctrine/dbal: 2.*
- doctrine/orm: 2.*
- symfony/symfony: 3.*
- twig/twig: 1.*
This package is auto-updated.
Last update: 2024-09-29 05:08:22 UTC
README
随着GDPR成为业务关键,这里有一个处理数据加密层的包。
安装
composer require brandoriented/doctrine-encryption-bundle dev-master
app/AppKernel.php public function registerBundles() { $bundles = [ ... new BrandOriented\Encryption\DoctrineEncryptionBundle(), ... ]; }
配置
基本
基本配置将利用提供的加密库。
doctrine_encryption: key: 'an encryption key' iv: 'an encryption iv' suffix: 'an encryption suffix'
完整
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
使用
在控制器中使用加密服务
use BrandOriented\Encryption\Bridge\Bridge; $this->get(Bridge::class)->encrypt($string) $this->get(Bridge::class)->decrypt($string);
实体注解
use BrandOriented\Encryption\Annotation\Encrypted; class User { /** * @Encrypted() */ private $firstname; }
上述代码将在prePersist
和preUpdate
时自动加密。
Twig
{{ user.firstname | decrypt }}
设计决策
您会注意到没有postLoad
事件来转换回解密。根据对doctrine的经验,当实体发生变化时,它会将其添加到队列中以便刷新。比如说,如果您有一个有1000个用户的账户,每个用户都会被解密,这意味着需要重新保存。
如何添加自定义加密器
创建一个继承自BrandOriented\Encryption\Encryptor\EncryptorInterface
的类。然后按照上述配置进行注册。
测试
是的,有很多可爱的单元测试 :)
路线图
- 表单输入
- 命令行工具
- Travis集成