bestyii/yii2-encrypter
最新稳定版本:v1.0.0
Composer 安装命令:
composer require bestyii/yii2-encrypter
包简介
Encryption data for Yii2
README 文档
README
兼容 mcrypt_encrypt及 openssl_encrypt
安装
The preferred way to install this extension is through composer.
Either run
php composer.phar require --prefer-dist bestyii/yii2-encrypter "*"
or add
"bestyii/yii2-encrypter": "*"
to the require section of your composer.json file.
配置
配置文件中加入
return [ //... 'components' => [ //... 'encrypter' => [ 'class' => 'bestyii\encrypter\Encrypter', 'key' => '32bit string', 'iv' => '32bit string', ], ], ];
如何使用
手动
You can now use the encrypter manually in any part of the application to either encrypt a string
\Yii::$app->encrypter->encrypt('string to encrypt');
or decrypt and encrypted string
\Yii::$app->encrypter->decrypt('string to decrypt');
使用Behavior自动加密/解密
The extension also comes with a behavior that you can easily attach to any ActiveRecord Model.
Use the following syntax to attach the behavior.
public function behaviors() { return [ 'encryption' => [ 'class' => '\bestyii\encrypter\EncrypterBehavior', 'attributes' => [ 'attributeName', 'otherAttributeName', ], ], ]; }
The behavior will automatically encrypt all the data before saving it on the database and decrypt it after the retrieve.
Keep in mind that the behavior will use the current configuration of the extension for the encryption.
统计信息
- 总下载量: 135
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2022-08-19