PHP code example of jsq / psr6-encrypting-decorator

1. Go to this page and download the library: Download jsq/psr6-encrypting-decorator 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/ */

    

jsq / psr6-encrypting-decorator example snippets


$encryptedCache = new \Jsq\CacheEncryption\Password\PoolDecorator(
    $cache, // an instance of \Psr\Cache\CacheItemPoolInterface
    $password,
    $cipher // optional, defaults to 'aes-256-cbc'
);

$cache->save($cache->getItem('normal_cache_data')->set('Totally normal!'));

$encryptedCache->save($encryptedCache->getItem('api_key')->set('super_secret'));

var_dump($encryptedCache->getItem('api_key')->get());
// string(12) "super_secret"

var_dump($cache->getItem('api_key')->get());
// class Jsq\CacheEncryption\Password\EncryptedValue#177 (4) {
//     private $mac =>
//     string(64) <hexits>
//     private $cipherText =>
//     string(44) <base64 encoded value>
//     private $method =>
//     string(11) "aes-256-cbc"
//     private $initializationVector =>
//     string(16) <binary string>
// }

var_dump($cache->getItem('normal_cache_data')->isHit());
// bool(true)

var_dump($encryptedCache->getItem('normal_cache_data')->isHit());
// bool(false)

$encryptedCache = new \Jsq\CacheEncryption\Envelope\PoolDecorator(
    $cache,
    'file:///path/to/certificate.pem',
    'file:///path/to/private/key.pem',
    $passphrase_for_private_key_file, // optional, defaults to null
    $cipher // optional, defaults to 'aes-256-cbc'
);