snicco/encryption-bundle

v2.0.0-beta.9 2024-09-07 14:27 UTC

README

codecov Psalm Type-Coverage Psalm level PhpMetrics - Static Analysis PHP-Versions

This WordPress bundle integrates defuse/php-encryption in applications based on snicco/kernel.

Make sure you have a read the documentation of defuse/php-encryption.

Installation

composer install snicco/encryption-bundle

Configuration

See config/encryption.php for the available configuration options.

If this file does not exist in your configuration directory the default configuration will be copied the first time the kernel is booted in dev mode.

The EncryptionOption::KEY_ASCII is intentionally set to a value that will throw an exception.

MAKE SURE TO READ THE DOCUMENTATION IN THE config/encryption.php FILE.

Usage

You must first generate a valid defuse key by running:

vendor/bin/vendor/bin/generate-defuse-key

MAKE SURE TO READ THE DOCUMENTATION IN THE config/encryption.php FILE to determine the best way to load the output of the above command into your configuration.

Add the EncryptionBundle to your bundles.php config file.

<?php
// /path/to/configuration/bundles.php

use Snicco\Bundle\Encryption\EncryptionBundle;

return [
    
    'bundles' => [
        Snicco\Component\Kernel\ValueObject\Environment::ALL => [
           EncryptionBundle::class
        ]   
    ]   
];

You can now lazily resolve the DefuseEncryptor from the booted kernel.

use Snicco\Bundle\Encryption\DefuseEncryptor;
use Snicco\Component\Kernel\Kernel;

/**
* @var Kernel $kernel
*/
$kernel->boot();

$defuse = $kernel->container()->make(DefuseEncryptor::class);

$plaintext = 'snicco.io';

$ciphertext = $defuse->encrypt($plaintext);

var_dump($plaintext === $ciphertext); // false 

$plain2 = $defuse->decrypt($ciphertext);

var_dump($plaintext === $plain2); // true 

Contributing

This repository is a read-only split of the development repo of the Snicco project.

This is how you can contribute.

Reporting issues and sending pull requests

Please report issues in the Snicco monorepo.

Security

If you discover a security vulnerability within BetterWPCache, please follow our disclosure procedure.