aviwar / doctrine-encrypt
该包通过生命周期事件加密和解密 Doctrine 字段。
1.0.0
2019-02-22 10:59 UTC
Requires
- php: >=7.1
- ext-openssl: *
- doctrine/orm: ~2.5
This package is auto-updated.
Last update: 2024-09-06 09:48:08 UTC
README
该包通过生命周期事件加密和解密 Doctrine 字段。
安装
按照以下方法将 aviwar/doctrine-encrypt 添加到您的 Composer 清单中。
{ "require": { "aviwar/doctrine-encrypt": "~1.0" } }
配置
将事件订阅者添加到实体管理器的的事件管理器中。假设 $em 是您的配置实体管理器
<?php $subscriber = new DoctrineEncryptSubscriber( new \Doctrine\Common\Annotations\AnnotationReader, new \DoctrineEncrypt\Encryptors\OpenSslEncryptor($secretKey) ); AnnotationRegistry::registerLoader('class_exists'); $eventManager = $em->getEventManager(); $eventManager->addEventSubscriber($subscriber);
注意:对于256位 $secretKey,请使用 RandomKeyGen
用法
<?php namespace Your\CoolNamespace; use Doctrine\ORM\Mapping\{Id, Column, GeneratedValue}; use DoctrineEncrypt\Configuration\Encrypted; /** * @Entity */ class Entity { /** * @Id * @GeneratedValue(strategy="AUTO") * @Column(type="integer") */ protected $id; /** * @Column(type="text") * @Encrypted */ protected $secret_data; }
许可证
此包受 MIT 许可证的保护。请参阅包中的完整许可证。
版本
我使用语义版本控制,如此处所述。