nepda/ doctrine-encrypt
此包已被废弃,不再维护。未建议替代包。
该包通过生命周期事件加密和解密Doctrine字段。
v7.0.1
2017-11-24 11:12 UTC
Requires
- php: >=7.1
- ext-openssl: *
- doctrine/orm: ~2.5
Requires (Dev)
- phpunit/phpunit: ~5.7
README
该包通过生命周期事件加密和解密Doctrine字段。Doctrine Encrypt包的此版本具有以下特点:
- 优秀的注解解析和缓存,使用Doctrine内置库以获得优异的性能
- 完全透明的字段加密:值仅在数据库中加密,永远不会在值中加密
- 单元测试
测试
当前测试运行于PHP 7.1, 7.2
安装
将 nepda/doctrine-encrypt
添加到您的Composer清单中。
{ "require": { "nepda/doctrine-encrypt": "~7.0" } }
配置
使用ZF2
查看 doctrine-encrypt-module 在 https://github.com/nepda/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\AES256Encryptor($secret) ); $eventManager = $em->getEventManager(); $eventManager->addEventSubscriber($encrypt_subscriber);
使用
<?php namespace Your\CoolNamespace; 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许可。请参阅包中的完整许可
版本
我使用语义版本控制,如此处所述。