PHP code example of psamatt / mcrypt-service-provider

1. Go to this page and download the library: Download psamatt/mcrypt-service-provider 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/ */

    

psamatt / mcrypt-service-provider example snippets


$app->register(new Psamatt\Silex\Provider\McryptServiceProvider('unique_key', array(
        'cipher' => MCRYPT_RIJNDAEL_256, // optional
        'mode' => MCRYPT_MODE_CBC, // optional
        'iv_source' => MCRYPT_DEV_RANDOM, // optional
        'base64' => true|false, // optional. Default is true
        'auto_generate_iv' => true|false, // option. Default is false
    )));

$app['mcrypt']->generateIv();

$data = 'my string';
$encryptedKey = $app['mcrypt']->encrypt($data);

print $app['mcrypt']->decrypt($encryptedKey); // prints 'my string'

{{ object.method | mcrypt_encrypt }} // encrypt
{{ object.method | mcrypt_decrypt }} // decrypt