maxcrossan / yii_encryption
为Yii模型加密和解密数据库字段的一个简单行为
1.1
2018-05-23 19:58 UTC
Requires
- yiisoft/yii: ^1
Requires (Dev)
- yiisoft/yii: ^1
This package is not auto-updated.
Last update: 2024-09-29 05:21:11 UTC
README
为Yii模型加密和解密数据库字段的一个简单行为。在实现后,配置为加密的字段将在下次模型保存时进行加密。
安装
将以下内容添加到您的composer文件中,并运行 php composer.phar update
"require": { "maxcrossan/yii_encryption": "dev-master" },
在protected/config/main.php中配置Yii的securityManger组件
'components'=>array( 'securityManager'=>array( 'cryptAlgorithm' => 'rijndael-128', 'encryptionKey' => 'your-encryption-key' ) )
使用方法
简单地将以下内容添加到您的模型行为中,并包括您想加密的数据库列
public function behaviors(){ return array( 'EncryptionBehaviour'=>array( 'class'=>'application.vendor.maxcrossan.yii_encryption.src.EncryptionBehaviour', //Add the fields you wish to encrypt below 'encryptedFields'=>array( 'addressLine1', 'addressLine2', 'lastName', 'city', 'postcode', 'emailAddress', 'phone' ) ) ) }
加密的数据库列最好使用BLOB db类型
故障排除
如果您在模型中加载类时遇到问题,您可能需要在main.php中为vendor设置一个别名,例如 Yii::setPathOfAlias('vendor',dirname(__FILE__).'/../../vendor/');
,然后引用EncryptionBehaviour为 vendor.maxcrossan.yii_encryption.src.EncryptionBehaviour