PHPackages                             psamatt/mcrypt-service-provider - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. psamatt/mcrypt-service-provider

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

psamatt/mcrypt-service-provider
===============================

A simple wrapper of the mcrypt library for use within Silex

1.0.2(12y ago)15061MITPHPPHP &gt;=5.3.2

Since Aug 31Pushed 12y ago1 watchersCompare

[ Source](https://github.com/psamatt/McryptServiceProvider)[ Packagist](https://packagist.org/packages/psamatt/mcrypt-service-provider)[ RSS](/packages/psamatt-mcrypt-service-provider/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (5)Used By (0)

Mcrypt Service Provider
=======================

[](#mcrypt-service-provider)

[![Build Status](https://camo.githubusercontent.com/70cb4a4e5727a1a9e6ac37271f18a2a7e3330b064f27edb3a84c67a9d095d019/68747470733a2f2f6170692e7472617669732d63692e6f72672f7073616d6174742f4d63727970745365727669636550726f76696465722e706e673f6272616e63683d6d6173746572)](https://api.travis-ci.org/psamatt/McryptServiceProvider)

A simple wrapper of the PHP [Mcrypt](http://www.php.net/manual/en/book.mcrypt.php) library for [Silex](http://silex.sensiolabs.org)

Usage
-----

[](#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

[](#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](http://github.com/psamatt/McryptServiceProvider/blob/master/tests/Psamatt/Silex/Provider/Tests/Mcrypt/McryptTest.php#L68) for further clarification.

Mcrypt Documentation
--------------------

[](#mcrypt-documentation)

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

- [Cipher](http://php.net/manual/en/mcrypt.ciphers.php)
- [Mode](http://php.net/manual/en/mcrypt.constants.php)
- [IV Source](http://php.net/manual/en/function.mcrypt-create-iv.php)

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`.

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 94.1% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

3

Last Release

4632d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/fa81051b9cb15d4cc4c836d4fddfa4b98f1ed094a232f255810a12b7d171bf2d?d=identicon)[psamatt](/maintainers/psamatt)

---

Top Contributors

[![psamatt](https://avatars.githubusercontent.com/u/1199265?v=4)](https://github.com/psamatt "psamatt (16 commits)")[![srsbiz](https://avatars.githubusercontent.com/u/1525842?v=4)](https://github.com/srsbiz "srsbiz (1 commits)")

---

Tags

mcryptsilex

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/psamatt-mcrypt-service-provider/health.svg)

```
[![Health](https://phpackages.com/badges/psamatt-mcrypt-service-provider/health.svg)](https://phpackages.com/packages/psamatt-mcrypt-service-provider)
```

###  Alternatives

[igorw/config-service-provider

A config ServiceProvider for Silex with support for php, json and yaml.

215636.5k13](/packages/igorw-config-service-provider)[franmomu/silex-pagerfanta-provider

Silex ServiceProvider for Pagerfanta Library

1312.1k](/packages/franmomu-silex-pagerfanta-provider)[emanueleminotto/faker-service-provider

Faker Service Provider for Silex

162.9k](/packages/emanueleminotto-faker-service-provider)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
