承接 nickcv/yii2-encrypter 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nickcv/yii2-encrypter

Composer 安装命令:

composer require nickcv/yii2-encrypter

包简介

Openssl Encrypter for Yii2

README 文档

README

Openssl Encrypter for Yii2 Version 1.1.0

This extension is used for two-way encryption. The cypher method used is AES, and you can either use the 128 bites or 256 bites encryption.

You can also decide whether you want to use base64 encoding on the encrypted string to make it easier to store it, keeping in mind that the additional encoding will always increase the size of the string.

Openssl has been used in place of mcrypt because of its sheer speed in the encryption and decryption process (up to 30 times faster).

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist nickcv/yii2-encrypter "*"

or add

"nickcv/yii2-encrypter": "*"

to the require section of your composer.json file.

Set Up

Once the extension is installed you can either add manually the configuration in the web.php file or you can use the command line installer that will randomly generate your encryption password and IV.

Manual Installation

Add the following lines in the components section of your web.php file.

return [
    'class'=>'\nickcv\encrypter\components\Encrypter',
    'globalPassword'=>'YourPassword',
    'iv'=>'YourIV',
    'useBase64Encoding'=>true,
    'use256BitesEncoding'=>false,
];

I recommend using base64 encoding to make it easier to store the encrypted string.

The IV must always be 16 bites long, keep that in mind in case you use multibyte characters.

Automatic Installation

Modify your console.php config file, adding the encrypter to the list of bootstrapped modules

'bootstrap' => ['log','encrypter'],

Add then the module to the module list

'modules' => [
    'encrypter' => 'nickcv\encrypter\Module',
],

At this point you will be able to simply execute from the root of your app directory the command ./yii encrypter/setup

The command will automatically generate the config file encrypter.php in your application config directory. The generated config file will contain a randomly generated password and IV.

You will now only have to add the extension to your web.php config file

'encrypter' => require(__DIR__ . DIRECTORY_SEPARATOR . 'encrypter.php'),

Basic Usage

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' => '\nickcv\encrypter\behaviors\EncryptionBehavior',
            '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.

Console Commands

If the console module is installed you can also use the ./yii encrypter/encrypt and ./yii encrypter/decrypt console commands.

To find out how to install the console module follow the "Automatic Installation" instructions in this document.

Unit Testing

The entire extension was built with TDD. To launch the tests just go inside the extension directory and execute the codecept run command.

Warnings

It is extremely hard to decrypt the data without the password and IV, keep a copy of them to avoid losing all your data.

Two-way encryption should not be used to store passwords: you should use a one-way encryption function like sha1 and a SALT

nickcv/yii2-encrypter 适用场景与选型建议

nickcv/yii2-encrypter 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 675.92k 次下载、GitHub Stars 达 19, 最近一次更新时间为 2015 年 01 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「Active Record」 「extension」 「Behavior」 「encryption」 「openssl」 「yii2」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 nickcv/yii2-encrypter 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 nickcv/yii2-encrypter 我们能提供哪些服务?
定制开发 / 二次开发

基于 nickcv/yii2-encrypter 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 675.92k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 19
  • 点击次数: 30
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 19
  • Watchers: 5
  • Forks: 17
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0
  • 更新时间: 2015-01-23