PHP code example of gtt / crypt-bundle

1. Go to this page and download the library: Download gtt/crypt-bundle 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/ */

    

gtt / crypt-bundle example snippets


use Gtt\Bundle\CryptBundle\Encryption\EncryptorInterface;
use Gtt\Bundle\CryptBundle\Encryption\DecryptorInterface;

class MyMagicService
{    
    /**
     * Encryptor
     *
     * @var EncryptorInterface
     */
    protected $encryptor;
 
    /**
     * Decryptor
     *
     * @var DecryptorInterface
     */
    protected $decryptor;
    
    public function __construct(EncryptorInterface $encryptor, DecryptorInterface $decryptor)
    {
        $this->encryptor = $encryptor;
        $this->decryptor = $decryptor;
    }
    
    public function doSomeMagic()
    {
        $someStringData = "Crypt me!";
        $encrypted = $this->encryptor->encrypt($someStringData);
        $decrypted = $this->decryptor->decrypt($encrypted);
        
        return $someStringData == $decrypted;
    }
}

use Gtt\Bundle\CryptBundle\Bridge\Doctrine\DBAL\Enum\TypeEnum;

$this->connection->executeQuery(
    'INSERT INTO something VALUES(:my_secret)',
    ['my_secret' => 'A very secret value'],
    ['my_secret' => TypeEnum::ENCRYPTED_STRING]
)

composer install zendframework/zend-crypt
composer install defuse/php-encryption