承接 dbublik/cryptography 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

dbublik/cryptography

最新稳定版本:v1.0.1

Composer 安装命令:

composer require dbublik/cryptography

包简介

A lightweight cryptography library for string encryption and decryption

README 文档

README

PHP Version Requirement License Tests Lint Code coverage Mutation score

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

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-03-09