Search by

Core library of the CryptyPHP Symfony bundle

Maintainers

Package info

github.com/crypty-php/core

pkg:composer/crypty-php/core

Transparency log

Statistics

Installs: 12

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

0.1.2 2026-09-02 20:27 UTC

This package is auto-updated.

Last update: 2026-09-02 20:28:08 UTC


README

CryptyPHP is a modern Symfony bundle that helps developer setting up encryption on targeted database columns, with flexible configuration and full customization.

Symfony >= 7.0 Symfony >= 8.0 PHP 8.2

🚀 Installation

composer require crypty-php/core

By default, CryptyPHP comes empty đŸ•ŗī¸. In order to make it work, you must select your implementation. At the moment, CryptyPHP only provides implementations for Doctrine, for the column collecting part, and Halite for the encryption part.

You can install the full package by running the following command :

composer require crypty-php/core crypty-php/doctrine crypty-php/halite

If you don't want to use Halite, you can also create your own encryptor.

🔧 Configuration

CryptyPHP comes with a friendly configuration that allows developers to configure encryptors. Once configured, you can use it on targeted database columns.

Example of configuration using Halite :

crypty:
    encryptors:
        default:
            type: halite

âš ī¸ If crypty-php/halite is not installed, an Exception will be thrown.

Available types are :

đŸŽ¯ Target a column

Independently of your chosen implementation, CryptyPHP comes with a PHP attribute, called Encrypt, which is meant to be used on a property of a database model. This property is then flagged as a property that must be encrypted/decrypted.

use Crypty\Core\Attribute\Encrypt;

class Model
{
    #[Encrypt]
    public string $encrypted;
}

By default, a property will be encrypted using the default configuration. If you want to choose a specific configuration, you can !

use Crypty\Core\Attribute\Encrypt;

class Model
{
    #[Encrypt(usingConfig: 'other')]
    public string $encrypted;
}

âœī¸ Create a custom encryption provider

An encryption provider comes in two parts :

  • a key provider
  • an encryptor (which requires the key provider for obvious reasons)

Technically, the key provider is not mandatory. It is just here to hold the logic for key generation and reading.

To make a key provider, you must implement the Crypty\Core\Key\KeyProviderInterface interface :

/**
 * @implements KeyProviderInterface<MyKey>
 */
final readonly class MyKeyProvider implements KeyProviderInterface
{
    public function generate(array $config): string
    {
        // ...
    }
    
    public function load(array $config): MyKey
    {
        // ...
    }
}

â„šī¸ The generate method must return the file path of the key.

Anyway, let's talk real business now : the encryptor ! It must implement the Crypty\Core\Encryptor\EncryptorInterface interface :

final readonly class MyEncryptor implements EncryptorInterface
{
    public function encrypt(Property $property, array $config): string
    {
        // ...
    }
    
    public function decrypt(Property $property, array $config): mixed
    {
        // ...
    }
}

Then, you can simply inject your key provider into your encryptor in order to generate and retrieve the encryption key.

The $config parameter is the configuration defined for the encryptor config matching the encryptor class. Oh yeah, we didn't mention this yet...

By default, your custom encryptor is nothing without configuration. In order to use it, you will have to add it your YAML configuration, and attach it a custom class, which is your encryptor class :

crypty:
    encryptors:
        default:
            type: custom
            class: App\Encryption\MyEncryptor

Every property flagged with the Encrypt attribute and the default configuration will be encrypted/decrypted with your custom encryptor !

📁 Storage

By default, every generated will be generated into the project root directory. This is probably not what you want, unless you're a messy developer !

Thankfully, CryptyPHP comes with multiple ways to configure your storage directory. You can do it :

  • globally
  • by encryptor

Example :

crypty:
    encryptors:
        default:
            type: halite
            # For this specific encryptor
            storage_directory: '%kernel.project_dir%/config/halite'
    # Globally
    storage_directory: '%kernel.project_dir%/config/keys'

It is also possible to configure the filename of the key. By default, the name will match the encryptor name from the YAML configuration. The ".key" extension is always added.

For instance, for the default configuration, the name will be "default.key". In order to configure the name, you can use the filename option on an encryptor configuration :

crypty:
    encryptors:
        default:
            type: halite
            filename: Halite