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

WordPress 扩展集在基于 snicco/kernel 的应用中集成了 defuse/php-encryption

请确保您已阅读了 defuse/php-encryption 的文档。

安装

composer install snicco/encryption-bundle

配置

有关可用的配置选项,请参阅 config/encryption.php

如果配置目录中没有此文件,则在开发模式下启动内核第一次时将复制默认配置。

EncryptionOption::KEY_ASCII 故意设置为会抛出异常的值。

请务必阅读 config/encryption.php 文件中的文档.

用法

您必须首先通过运行以下命令生成有效的 defuse 密钥:

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

请务必阅读 config/encryption.php 文件中的文档 以确定将上述命令的输出加载到您的配置中的最佳方式。

EncryptionBundle 添加到您的 bundles.php 配置文件。

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

use Snicco\Bundle\Encryption\EncryptionBundle;

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

您现在可以从启动的内核中 懒加载 DefuseEncryptor

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 

贡献

此存储库是 Snicco 项目 开发仓库的只读分支。

以下是您可以如何进行贡献:.

报告问题和发送拉取请求

请在 Snicco monorepo 中报告问题。

安全性

如果您在 BetterWPCache 中发现安全漏洞,请遵循我们的 披露程序