vtlfokin / doctrine-encrypt
该软件包通过生命周期事件对Doctrine字段进行加密和解密。
v6.0.0
2017-03-12 17:38 UTC
Requires
- php: ^7.0
- doctrine/orm: ^2.5
Requires (Dev)
- illuminate/encryption: ^5.4
- phpunit/phpunit: ^5.7
This package is not auto-updated.
Last update: 2024-09-20 01:06:35 UTC
README
该软件包通过生命周期事件对Doctrine字段进行加密和解密。本版本的Doctrine Encrypt软件包具有以下特性:
- 高效的注解解析和缓存,使用Doctrine内置库以获得更高的性能
- 完全透明的字段加密:值仅在数据库中加密,永远不会在值中加密
- 单元测试
安装
将 vtlfokin/doctrine-encrypt 添加到您的Composer清单中。
{ "require": { "vtlfokin/doctrine-encrypt": "~5.0" } }
配置
使用ZF2
查看 doctrine-encrypt-module 在 https://github.com/51systems/doctrine-encrypt-module
手动
将事件订阅者添加到您的实体管理器的事件管理器中。假设 $em 是您配置的实体管理器
<?php //You should pick your own hexadecimal secret $secret = pack("H*", "dda8e5b978e05346f08b312a8c2eac03670bb5661097f8bc13212c31be66384c"); $subscriber = new DoctrineEncryptSubscriber( new \Doctrine\Common\Annotations\AnnotationReader, new \DoctrineEncrypt\Encryptors\CI2BlowfishEncryptor($secret) ); $eventManager = $em->getEventManager(); $eventManager->addEventSubscriber($encrypt_subscriber);
用法
<?php namespace Your\Namespace; use Doctrine\ORM\Mapping as ORM; use DoctrineEncrypt\Configuration\Encrypted; /** * @ORM\Entity */ class Entity { /** * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * @ORM\Column(type="integer") * @var int */ protected $id; /** * @ORM\Column(type="text") * @Encrypted * @var string */ protected $secret_data; }
许可证
此软件包采用MIT许可证。请参阅软件包中的完整许可证
版本
我正在使用语义版本控制,如此处所述。