PHP code example of satthi / encryption-support

1. Go to this page and download the library: Download satthi/encryption-support 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/ */

    

satthi / encryption-support example snippets




class AccountsTable extends Table
{

    public function initialize(array $config)
    {
        //behavior読み込み
        $this->addBehavior('EncryptionSupport.Encryption');
    }


//Traitの読み込み
use EncryptionSupport\Model\Entity\EncryptionTrait;

/**
 * Account Entity.
 */
class Account extends Entity
{
//Traitの読み込み
use EncryptionTrait;
    
    public $encryptConfig = [
        'type' => 'default',
        'fields' => [
            //暗号化を行いたいフィールド
            'name'
        ],
    ];
    
    //&getメソッドをoverride
    public function &__get($property){
        $value = parent::__get($property);
        
        $value = $this->getDecrypt($property, $value);
        
        return $value;
    }
    
    //setメソッドをoverride
    
    public function set($property, $value = null, array $options = []){
        
        parent::set($property, $value , $options);
        
        $this->setEncrypt();
        return $this;
    }


//適当なキー
define('ENCRYPTION_KEY','7UniidVg5tFIXcVjyEDmeRPAXzqWc55OEJqdsJXSejfHwyeAICSkYMjgNqPow2ke');