PHPackages                             assistenzde/simple-cryptographic-bundle - 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. [Security](/categories/security)
4. /
5. assistenzde/simple-cryptographic-bundle

ActiveSymfony-bundle[Security](/categories/security)

assistenzde/simple-cryptographic-bundle
=======================================

A simple cryptographic service to encode/decode an input string with openssl\_encrypt methods like aes128, aes256, blowfish and other cipher methods.

0.0(4y ago)026MITPHPPHP &gt;=7.4

Since Jul 1Pushed 4y ago2 watchersCompare

[ Source](https://github.com/assistenzde/simple-cryptographic-bundle)[ Packagist](https://packagist.org/packages/assistenzde/simple-cryptographic-bundle)[ Docs](https://github.com/assistenzde/simple-cryptographic-bundle)[ RSS](/packages/assistenzde-simple-cryptographic-bundle/feed)WikiDiscussions main Synced today

READMEChangelogDependencies (4)Versions (3)Used By (0)

Simple Cryptographic Bundle
===========================

[](#simple-cryptographic-bundle)

[![Latest Stable Version](https://camo.githubusercontent.com/10f822acff017288a2efdcb3641e61e89e478ad7ef21f74921844611955091c6/68747470733a2f2f706f7365722e707567782e6f72672f617373697374656e7a64652f73696d706c652d63727970746f677261706869632d62756e646c652f76657273696f6e)](https://packagist.org/packages/assistenzde/simple-cryptographic-bundle)[![Total Downloads](https://camo.githubusercontent.com/0126a4c16141704c116658db614ed84031a85619f5f673f00d958b2ddab13bde/68747470733a2f2f706f7365722e707567782e6f72672f617373697374656e7a64652f73696d706c652d63727970746f677261706869632d62756e646c652f646f776e6c6f616473)](https://packagist.org/packages/assistenzde/simple-cryptographic-bundle)[![License](https://camo.githubusercontent.com/6cd5ff374f2db1b6184dc269a9b9ad801e239c21032c54378b49928e3566b24c/68747470733a2f2f706f7365722e707567782e6f72672f617373697374656e7a64652f73696d706c652d63727970746f677261706869632d62756e646c652f6c6963656e7365)](https://packagist.org/packages/assistenzde/simple-cryptographic-bundle)[![PHP ≥v7.4](https://camo.githubusercontent.com/c8fd81777287d47d394aec964360257ba8d6849e38fc6f9ebcb5bd3807abbd90/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d25453225383925413537253245342d3030343461612e737667)](https://www.php.net/manual/en/migration72.new-features.php)[![Symfony ≥5](https://camo.githubusercontent.com/89235244d2b2f20c8057cd7d8bc3b2df2d0e91c6cae1bbec16d5049b0c15ed74/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f53796d666f6e792d254532253839254135352d3030343461612e737667)](https://symfony.com/)

The **SimpleCryptographicService** class contains method to encrypt/decrypt phrases with symmetric encryption. With the usage of [OpenSSL](https://www.php.net/manual/en/intro.openssl.php) each encoding of the same phrase results in a different encoded string.

Quick example usage:

```
$cryptographicService = new SimpleCryptographicService('$ecr3t');

$encryptedString1 = $cryptographicService->encrypt('Hello world!');  // some encrypted string, i.e. 'ABCDEFG'
echo $cryptographicService->decrypt($encryptedString1);              // outputs 'Hello world!'

$encryptedString2 = $cryptographicService->encrypt('Hello world!');  // some encrypted string, i.e. 'HIJKLMNOP'
echo $cryptographicService->decrypt($encryptedString2);              // outputs 'Hello world!'
```

This library can be used easily in Symfony projects but also in non-Symfony projects.

Table of Contents
-----------------

[](#table-of-contents)

- [Requirements](#requirements)
- [Installation](#installation)
- [Symfony Configuration](#symfony-configuration)
- [Usage](#usage)
- [Credits](#credits)

Requirements
------------

[](#requirements)

The usage of [**PHP ≥ v7.4**](https://www.php.net/manual/en/migration74.php)and [**Symfony ≥ 5**](https://symfony.com/doc/5.0/setup.html) is recommended.

Installation
------------

[](#installation)

Please install via [composer](https://getcomposer.org/).

```
composer require assistenzde/simple-cryptographic-bundle
```

The bundle will be automatically added to your `bundles.yaml` configuration.

Symfony Configuration
---------------------

[](#symfony-configuration)

By default the bundle depends on the `APP_SECRET` environment variable and uses the `aes-256-ctr` cipher method. If you want to use a custom cipher key **OR** a customer cipher method create the `config/packates/simple-cryptographic-bundle.yaml` configuration file and set the related values.

**simple-cryptographic-bundle.yaml**:

```
simple-cryptographic-bundle.yaml:
  # set a custom cipher key or comment out to use the default value
  # default is %kernel.secret% (which contains the APP_SECRET value)
  key: My-cu5t0m-c1ph3r-k3y
  # set a custom cipher method or comment out to use the default value
  # default is aes-256-ctr
  cipher: camellia-128-ofb
```

Usage
-----

[](#usage)

Use dependency injection to access the cryptographic service.

```
