PHPackages                             aditiyass/yii2-encrypter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. aditiyass/yii2-encrypter

ActiveYii2-extension[Security](/categories/security)

aditiyass/yii2-encrypter
========================

Openssl Encrypter for Yii2

1.1.2(1y ago)015GPL-3.0PHP

Since Jan 23Pushed 1y agoCompare

[ Source](https://github.com/aditiyass/yii2-encrypter)[ Packagist](https://packagist.org/packages/aditiyass/yii2-encrypter)[ RSS](/packages/aditiyass-yii2-encrypter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (1)Versions (7)Used By (0)

Openssl Encrypter for Yii2
==========================

[](#openssl-encrypter-for-yii2)

Openssl Encrypter for Yii2 Version 1.1.1

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
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

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

```

or add

```
"aditiyass/yii2-encrypter": "*"

```

to the require section of your `composer.json` file.

Set Up
------

[](#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
-----------

[](#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
--------

[](#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
----------------

[](#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
------------

[](#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
--------

[](#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**

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance42

Moderate activity, may be stable

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity67

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~730 days

Recently: every ~912 days

Total

6

Last Release

477d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8af9e8c57206f3475fb043ae0d3f4c0818a1eda26fdb0cb0f9db8e3222ecda83?d=identicon)[aditiya\_ss](/maintainers/aditiya_ss)

---

Top Contributors

[![aditiyass](https://avatars.githubusercontent.com/u/89702148?v=4)](https://github.com/aditiyass "aditiyass (3 commits)")

---

Tags

encryptionopensslyii2extensionBehavioractive-record

### Embed Badge

![Health badge](/badges/aditiyass-yii2-encrypter/health.svg)

```
[![Health](https://phpackages.com/badges/aditiyass-yii2-encrypter/health.svg)](https://phpackages.com/packages/aditiyass-yii2-encrypter)
```

###  Alternatives

[nickcv/yii2-encrypter

Openssl Encrypter for Yii2

19640.0k1](/packages/nickcv-yii2-encrypter)[hyperia/yii2-secure-headers

Secure headers for your Yii2 app

21189.5k](/packages/hyperia-yii2-secure-headers)[v0lume/yii2-meta-tags

DB based model meta data for SEO

204.1k](/packages/v0lume-yii2-meta-tags)[juliardi/yii2-captcha

Captcha library wrapper for Yii2

167.9k](/packages/juliardi-yii2-captcha)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
