PHP code example of tiagocomti / yii2-cryptbox

1. Go to this page and download the library: Download tiagocomti/yii2-cryptbox library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tiagocomti / yii2-cryptbox example snippets


//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
],

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

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',
];


namespace app\db;

use app\helpers\Strings;
use yii\db\Exception;

class Connection extends \yii\db\Connection
{
    /**
     * @throws Exception
     */
    public function __construct($config = [])
    {
        \Yii::info("Iniciando base de dados", "api");
        return parent::__construct([
            'dsn' => $config["dsn"],
            'username' => $config["username"],
            'password' => Cryptbox::decryptDBPass($config["password"]),
            'charset' => $config["charset"],
        ]);
    }
}

return Cryptbox::safeWriteInFile("/tmp/teste", "teste", Cryptbox::getOurSecret());

return Cryptbox::safeWriteInFile("/tmp/teste", "teste", "Very Nice Secret");
sh
php yii cryptBox/crypt/db-password
sh
php yii cryptBox/crypt/check-db
sh
php yii cache/flush-all