PHPackages                             tiagocomti/yii2-cryptbox - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. tiagocomti/yii2-cryptbox

ActiveYii2-extension[Utility &amp; Helpers](/categories/utility)

tiagocomti/yii2-cryptbox
========================

Easy cryptbox for you guys

v1.0.23(2y ago)24.4k↓76%BSD-3-ClausePHPPHP &gt;=7.2 || ^8.1 || ^8.2

Since Jan 24Pushed 2y ago1 watchersCompare

[ Source](https://github.com/tiagocomti/yii2-cryptbox)[ Packagist](https://packagist.org/packages/tiagocomti/yii2-cryptbox)[ RSS](/packages/tiagocomti-yii2-cryptbox/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (10)Dependencies (2)Versions (24)Used By (0)

 [ ![](https://camo.githubusercontent.com/81ec358406bf93fcec3398b5b8f55c5542faa74d405e969e9e15818a737c23fe/68747470733a2f2f63646e2e646973636f72646170702e636f6d2f6174746163686d656e74732f3731303138323131333339353231323337382f3933363236383833353035313430353334332f7365677572612e706e67) ](https://github.com/yiisoft)

Yii 2 Encrypt class util
========================

[](#yii-2-encrypt-class-util)

Use the [Yii 2](http://www.yiiframework.com/) application best for rapidly creating small projects.

This class has as business purposes to facilitate and demystify the difficulty of encrypting data using php

This first project works together, a standalone version is being developed

[![Latest Stable Version](https://camo.githubusercontent.com/46cc517e06dacd4b704b373dddb7bf3ca5e95e13a167c53be1bc0f4360a88a04/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f796969736f66742f796969322d6170702d62617369632e737667)](https://packagist.org/packages/yiisoft/yii2-app-basic)[![Total Downloads](https://camo.githubusercontent.com/94888011ac494bc9509c512d0c4470390af0655c8418781e58f106e9da85b53d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f796969736f66742f796969322d6170702d62617369632e737667)](https://packagist.org/packages/yiisoft/yii2-app-basic)[![build](https://github.com/yiisoft/yii2-app-basic/workflows/build/badge.svg)](https://github.com/yiisoft/yii2-app-basic/actions?query=workflow%3Abuild)

DIRECTORY STRUCTURE
-------------------

[](#directory-structure)

```
  yii2-cryptbox/        Main folter of our project
     |
     | - commands/          Folter to easy commands for generate your keys
     | - helpers/           Helpers

```

REQUIREMENTS
------------

[](#requirements)

- The minimum requirement by this project template that your Web server supports PHP 5.6.0.
- Yii2 stable
- Libsodium

INSTALLATION
------------

[](#installation)

### Install via Composer

[](#install-via-composer)

If you do not have [Composer](http://getcomposer.org/), you may install it by following the instructions at [getcomposer.org](http://getcomposer.org/doc/00-intro.md#installation-nix).

```
composer --prefer-dist tiagocomti/yii2-cryptbox

```

Now you be able to call our class like:

```
Cryptbox::generateKeyPair("ANY_SALT_YOU_WANT")
```

CONFIGURATION
-------------

[](#configuration)

### Database

[](#database)

Edit the file `config/web.php or console.php` and add this:

```
//Keep this name
'cryptbox' => [
   'class' => 'tiagocomti\cryptbox\Cryptbox',
   //A path to save our keys.
   'keysPath' =>  __DIR__."/../../keys/",
   // Execute: php yii cryptBox/crypt/encode '{Your key}'
   // This key will be used for
   'secret' => '{"1":95,"2":86,"3":65,"4":77,"5":79,"6":83,"7":66,"8":82,"9":73,"10":78,"11":68,"12":65,"13":82,"14":79,"15":72,"16":79,"17":74,"18":69,"19":65,"20":77,"21":65,"22":78,"23":72,"24":65,"25":83,"26":79,"27":65,"28":68,"29":69,"30":85,"31":83,"32":95}',
   // Less security but faster
   'enableCache' => true,
   //In seconds
   'timeCache' => 800
],
```

Edit the file ` console.php` and add this:

```
'modules' => [
     // ... other modules ...
     'cryptBox' => [
         'class' => 'tiagocomti\cryptbox\commands\Module',
     ],
 ],
```

**NOTES:**

- Check and edit the other files in the `config/` directory to customize your application as required.

Samples
-------

[](#samples)

\###Keep your db password safe in php file - PERSONAL TIP

we need to set encrypt our password, use this command

This command will request for you a pass, NEVER pass your pass in command line, wait for shell input.

```
php yii cryptBox/crypt/db-password
```

```
php yii cryptBox/crypt/db-password
password: very_nice_pass_for_my_db
Paste it in your db conf:
{"1":67,"2":87,"3":55,"4":108,"5":86,"6":103,"7":122,"8":75,"9":79,"10":80,"11":87,"12":118,"13":106,"14":56,"15":72,"16":104,"17":47,"18":86,"19":98,"20":74,"21":116,"22":70,"23":52,"24":107,"25":50,"26":66,"27":51,"28":114,"29":65,"30":90,"31":87,"32":100,"33":53,"34":71,"35":89,"36":86,"37":106,"38":122,"39":54,"40":89,"41":109,"42":98,"43":81,"44":55,"45":48,"46":81,"47":118,"48":86,"49":111,"50":109,"51":71,"52":52,"53":73,"54":72,"55":112,"56":75,"57":50,"58":51,"59":74,"60":57,"61":77,"62":80,"63":67,"64":52,"65":50,"66":119,"67":80,"68":98,"69":113,"70":117,"71":72,"72":79,"73":113,"74":54,"75":83,"76":52,"77":74,"78":90,"79":71,"80":118,"81":66,"82":74,"83":117,"84":114,"85":56,"86":65,"87":61,"88":61}
```

in your `config/db.php`, we need to create our own Connection class and set our new encrypt password

```
return [
    //Set your own db/connection class.
    'class' => 'app\db\Connection',
    'dsn' => 'mysql:host=127.0.0.1;dbname=database_name',
    'username' => 'user_db',
    'password' => '{"1":67,"2":87,"3":55,"4":108,"5":86,"6":103,"7":122,"8":75,"9":79,"10":80,"11":87,"12":118,"13":106,"14":56,"15":72,"16":104,"17":47,"18":86,"19":98,"20":74,"21":116,"22":70,"23":52,"24":107,"25":50,"26":66,"27":51,"28":114,"29":65,"30":90,"31":87,"32":100,"33":53,"34":71,"35":89,"36":86,"37":106,"38":122,"39":54,"40":89,"41":109,"42":98,"43":81,"44":55,"45":48,"46":81,"47":118,"48":86,"49":111,"50":109,"51":71,"52":52,"53":73,"54":72,"55":112,"56":75,"57":50,"58":51,"59":74,"60":57,"61":77,"62":80,"63":67,"64":52,"65":50,"66":119,"67":80,"68":98,"69":113,"70":117,"71":72,"72":79,"73":113,"74":54,"75":83,"76":52,"77":74,"78":90,"79":71,"80":118,"81":66,"82":74,"83":117,"84":114,"85":56,"86":65,"87":61,"88":61}',
    'charset' => 'utf8',
];
```

Look that example of our new Connection class

```
