PHPackages                             tobento/app-encryption - 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. tobento/app-encryption

ActiveLibrary[Security](/categories/security)

tobento/app-encryption
======================

App encryption support.

2.0(7mo ago)052—0%3MITPHPPHP &gt;=8.4

Since Jun 13Pushed 7mo ago1 watchersCompare

[ Source](https://github.com/tobento-ch/app-encryption)[ Packagist](https://packagist.org/packages/tobento/app-encryption)[ Docs](https://www.tobento.ch)[ RSS](/packages/tobento-app-encryption/feed)WikiDiscussions 2.x Synced 1mo ago

READMEChangelog (3)Dependencies (7)Versions (5)Used By (3)

App Encryption
==============

[](#app-encryption)

Encryption support for the app.

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

[](#table-of-contents)

- [Getting Started](#getting-started)
    - [Requirements](#requirements)
- [Documentation](#documentation)
    - [App](#app)
    - [Encryption Boot](#encryption-boot)
        - [Encryption Config](#encryption-config)
        - [Encryption Usage](#encryption-usage)
- [Credits](#credits)

---

Getting Started
===============

[](#getting-started)

Add the latest version of the app encryption project running this command.

```
composer require tobento/app-encryption

```

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

[](#requirements)

- PHP 8.4 or greater

Documentation
=============

[](#documentation)

App
---

[](#app)

Check out the [**App Skeleton**](https://github.com/tobento-ch/app-skeleton) if you are using the skeleton.

You may also check out the [**App**](https://github.com/tobento-ch/app) to learn more about the app in general.

Encryption Boot
---------------

[](#encryption-boot)

The encryption boot does the following:

- installs and loads encryption config file
- (re)generates encryption keys for config file
- implements encryption interfaces based on encryption config

```
use Tobento\App\AppFactory;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\Encryption\Boot\Encryption::class);

// Run the app:
$app->run();
```

You may check out the [**Encryption Service**](https://github.com/tobento-ch/service-encryption) to learn more about it.

### Encryption Config

[](#encryption-config)

The configuration for the encryption is located in the `app/config/encryption.php` file at the default App Skeleton config location where you can specify the encrypters for your application.

**Regenerating encryption keys**

If you want to regenerate encryption keys, simply replace the existing key with `{any-unique-name}` in the `app/config/encryption.php` file. On the next booting, it will regenerate it automatically.

```
return [

    //...

    /*
    |--------------------------------------------------------------------------
    | Encrypters
    |--------------------------------------------------------------------------
    |
    | Specify the encrypters for your application.
    |
    */

    'encrypters' => [

        'default' => [
            // must implement EncrypterFactoryInterface
            'factory' => Crypto\EncrypterFactory::class,

            'config' => [
                // replace existing key:
                'key' => '{default-encrypt-key}',
            ],

            // must implement KeyGeneratorInterface
            'keyGenerator' => Crypto\KeyGenerator::class,
        ],

    ],
];
```

### Encryption Usage

[](#encryption-usage)

You can access the encrypter(s) in several ways:

**Using the app**

```
use Tobento\App\AppFactory;
use Tobento\Service\Encryption\EncryptersInterface;
use Tobento\Service\Encryption\EncrypterInterface;

// Create the app
$app = new AppFactory()->createApp();

// Add directories:
$app->dirs()
    ->dir(realpath(__DIR__.'/../'), 'root')
    ->dir(realpath(__DIR__.'/../app/'), 'app')
    ->dir($app->dir('app').'config', 'config', group: 'config')
    ->dir($app->dir('root').'public', 'public')
    ->dir($app->dir('root').'vendor', 'vendor');

// Adding boots:
$app->boot(\Tobento\App\Encryption\Boot\Encryption::class);
$app->booting();

// using the default encrypter:
$encrypter = $app->get(EncrypterInterface::class);

// using a specified encrypter:
$encrypters = $app->get(EncryptersInterface::class);

$cookieEncrypter = $encrypters->get('cookies');

// you may check if the encrypter exists:
var_dump($encrypters->has('cookies'));
// bool(true)

// encrypt and decrypt:
$encrypted = $encrypter->encrypt('something');

$decrypted = $encrypter->decrypt($encrypted);

// Run the app:
$app->run();
```

**Using autowiring**

You can also request the `EncryptersInterface::class` or `EncrypterInterface::class` in any class resolved by the app.

```
use Tobento\Service\Encryption\EncryptersInterface;
use Tobento\Service\Encryption\EncrypterInterface;

class SomeService
{
    public function __construct(
        protected EncryptersInterface $encrypters,
        protected EncrypterInterface $encrypter,
    ) {}
}
```

**Using the view boot**

```
use Tobento\App\Boot;
use Tobento\App\Encryption\Boot\Encryption;

class AnyServiceBoot extends Boot
{
    public const BOOT = [
        // you may ensure the encryption boot.
        Encryption::class,
    ];

    public function boot(Encryption $encryption)
    {
        $encrypter = $encryption->encrypter();
        $encrypters = $encryption->encrypters();
    }
}
```

You may check out the [**Encryption Service**](https://github.com/tobento-ch/service-encryption) to learn more about it.

Credits
=======

[](#credits)

- [Tobias Strub](https://www.tobento.ch)
- [All Contributors](../../contributors)

###  Health Score

40

—

FairBetter than 88% of packages

Maintenance63

Regular maintenance activity

Popularity10

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~210 days

Total

5

Last Release

228d ago

Major Versions

1.x-dev → 2.02025-10-01

PHP version history (2 changes)1.0.0PHP &gt;=8.0

2.0PHP &gt;=8.4

### Community

Maintainers

![](https://www.gravatar.com/avatar/055d6a1b5c2384bb179c75ab0b55914231d898fdc4dffeb30770f81200e52206?d=identicon)[TOBENTOch](/maintainers/TOBENTOch)

---

Top Contributors

[![tobento-ch](https://avatars.githubusercontent.com/u/16684832?v=4)](https://github.com/tobento-ch "tobento-ch (4 commits)")

---

Tags

packageencryptionapptobento

###  Code Quality

TestsPHPUnit

Static AnalysisPsalm

Type Coverage Yes

### Embed Badge

![Health badge](/badges/tobento-app-encryption/health.svg)

```
[![Health](https://phpackages.com/badges/tobento-app-encryption/health.svg)](https://phpackages.com/packages/tobento-app-encryption)
```

PHPackages © 2026

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