PHP code example of pollen-solutions / encryption

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

    

pollen-solutions / encryption example snippets


use Pollen\Encryption\Encrypter;

// Cypher (AES-128-CBC|AES-256-CBC) and Key definitions
$cypher = 'AES-256-CBC';
// Recommended (use a static key. Replace 'static_key' by your own string)
$key = md5('static_key');
// Dynamic random key (only valid during current request)
// $key = Encrypter::generateKey($cypher);

// Encrypter instanciation
$encrypter = new Encrypter($key, $cypher);

// To encrypt string
$toEncrypt = 'toEncrypt';

// Encryption
$encrypted = $encrypter->encrypt($toEncrypt);
var_dump('encrypted string : ' . $encrypted);
// ex. eyJpdiI6ImwxcmNicytwcVpkZmdsem4zTEpROVE9PSIsInZhbHVlIjoiK0JTN2EzWFVFazJoYi9abk1maW4vZz09IiwibWFjIjoiNDFiMzNlNzJkZjQxNGNhNmQyYmQ3MmViYjc0MTMyNmZiOTJmZTdlNDNmZmZiZGM3NzE1ZTc5YzE3YjIyZGQwZCJ9 

// Décryption
$decrypted = $encrypter->decrypt($encrypted);
var_dump('decrypted string : ' . $decrypted);
// >> toEncrypt