psamatt/mcrypt-service-provider
Composer 安装命令:
composer require psamatt/mcrypt-service-provider
包简介
A simple wrapper of the mcrypt library for use within Silex
README 文档
README
A simple wrapper of the PHP Mcrypt library for Silex
Usage
Register the service provider and specify your unique key.
$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:
$app['mcrypt']->generateIv();
In your Silex application, you can use the Mcrypt provider with the following lines:
$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:
{{ 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
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.
Mcrypt Documentation
For more information on what values to use for Mcrypt, view the documentation on each specific type:
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.
统计信息
- 总下载量: 506
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-08-30