dbublik/cryptography
最新稳定版本:v1.0.1
Composer 安装命令:
composer require dbublik/cryptography
包简介
A lightweight cryptography library for string encryption and decryption
README 文档
README
Need to encrypt and decrypt strings effortlessly? Encrypter does it for you with just two simple methods.
Installation
composer require dbublik/cryptography
Usage
Initialize encrypter:
use DBublik\Cryptography\Encrypter; $secretKey = 'your_secret_key'; $encrypter = Encrypter::create($secretKey);
or prepare it for a container, e.g. for Symfony:
// config/services.php namespace Symfony\Component\DependencyInjection\Loader\Configurator; use DBublik\Cryptography\Encrypter; return function(ContainerConfigurator $container): void { $services = $container->services(); $services->set(Encrypter::class) ->factory([null, 'create']) ->args([env('YOUR_SECRET_KEY')]); };
Available encryption algorithms: aes-128-gcm, aes-192-gcm and aes-256-gcm (by default).
Encrypt:
final readonly class ExampleService { public function __construct( private \DBublik\Cryptography\Encrypter $encrypter, ) {} public function save(#[\SensitiveParameter] string $sensitiveValue): void { $encryptedValue = $this->encrypter->encrypt($sensitiveValue); // Don't forget to save $encryptedValue somewhere } }
Decrypt:
final readonly class ExampleService { public function __construct( private \DBublik\Cryptography\Encrypter $encrypter, ) {} public function doSomething(string $encryptedValue): mixed { $sensitiveValue = $this->encrypter->decrypt($encryptedValue); // Be careful! Do not show $sensitiveValue to anyone } }
Supported PHP versions
PHP 8.2 and later.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-09