2017 © Pedro Peláez
 

library mcrypt-service-provider

A simple wrapper of the mcrypt library for use within Silex

image

psamatt/mcrypt-service-provider

A simple wrapper of the mcrypt library for use within Silex

  • Monday, September 2, 2013
  • by psamatt
  • Repository
  • 1 Watchers
  • 1 Stars
  • 367 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 5 Versions
  • 4 % Grown

The README.md

Mcrypt Service Provider

Build Status, (*1)

A simple wrapper of the PHP Mcrypt library for Silex, (*2)

Usage

Register the service provider and specify your unique key., (*3)

$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
    )));

Please note that you must explicitly generate the IV if you leave auto_generate_iv to false, you can do this by the following:, (*4)

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

In your Silex application, you can use the Mcrypt provider with the following lines:, (*5)

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

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

If you'd like to use mcrypt in your Twig templates*, you can using either the mcrypt_encrypt or the mcrypt_decrypt filter:, (*6)

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

* ensure you define the McryptServiceProvider after your Twig Service Provider to utilise the Twig feature, (*7)

Other useful information

If you require to decrypt a mcrypt encrypted string and are not using MCRYPT_MODE_ECB (recommended), you must initially get the IV before you've encrypted your string using $app['mcrypt']->getIv() and store this safely, then when you are ready to decrypt, you must set the same IV using $app['mcrypt']->setIv($my_iv), view the unit test for further clarification., (*8)

Mcrypt Documentation

For more information on what values to use for Mcrypt, view the documentation on each specific type:, (*9)

By default, the encrypted string will use base 64 encoding and decoding, to set this for your application, set the base64 option to true or false., (*10)

The Versions

02/09 2013

dev-master

9999999-dev

A simple wrapper of the mcrypt library for use within Silex

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Goodwin

silex mcrypt

02/09 2013

dev-bugfixes

dev-bugfixes

A simple wrapper of the mcrypt library for use within Silex

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Goodwin

silex mcrypt

02/09 2013

1.0.2

1.0.2.0

A simple wrapper of the mcrypt library for use within Silex

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Goodwin

silex mcrypt

01/09 2013

1.0.1

1.0.1.0

A simple wrapper of the mcrypt library for use within Silex

  Sources   Download

MIT

The Requires

 

The Development Requires

by Matt Goodwin

silex mcrypt

31/08 2013

1.0.0

1.0.0.0

A simple wrapper of the mcrypt library for use within Silex

  Sources   Download

MIT

The Requires

 

by Matt Goodwin

silex mcrypt