manojx/encrypter-bundle
Composer 安装命令:
composer require manojx/encrypter-bundle
包简介
A Symfony bundle to encrypt and decrypt data using AES-256-CBC encryption.
README 文档
README
Purpose
The Encrypter Bundle provides a simple and secure way to encrypt and decrypt data using the AES-256-CBC encryption algorithm. This bundle is designed for Symfony applications, allowing developers to protect sensitive information with ease. With built-in support for key generation and salt handling, the Encrypter Bundle helps ensure that your data remains secure.
Features
- Secure Encryption: Uses AES-256-CBC for data protection.
- Key Management: Supports random key and salt generation.
- Easy Integration: Seamlessly integrates with Symfony applications.
Installation
To install the Encrypter Bundle, run the following command:
composer require manojx/encrypter-bundle
Configuration
To configure the Encrypter Bundle, you need to create a configuration file. Follow these steps:
- Create the Configuration File: Navigate to the
config/packagesdirectory of your Symfony project and create a new file namedencrypter.yaml.
touch config/packages/encrypter.yaml
- Add Configuration Content: Open the newly created encrypter.yaml file in your text editor and add the following content:
encrypter: secret: 'your16-32-64key' # Replace with your actual secret key
Ensure that the secret key is either 16, 32, or 64 bytes long. This key will be used for encryption and decryption operations.
Available Methods
The Encrypter Bundle provides several methods for encryption, decryption, key generation, and salt generation. Below is a list of each method along with a brief description:
encrypt(string $data, ?string $salt = null): string
Encrypts the given data using the AES-256-CBC encryption algorithm.
-
Parameters:
string $data: The plaintext data to encrypt.string|null $salt: An optional salt to use for key derivation.
-
Returns: The encrypted data, encoded in Base64 format, including the initialization vector (IV).
decrypt(string $data, ?string $salt = null): string
Decrypts the given encrypted data.
-
Parameters:
string $data: The encrypted data to decrypt.string|null $salt: An optional salt that was used during encryption.
-
Returns: The original plaintext data.
-
Throws: An exception if decryption fails.
generateEncryptionKey(int $length = 32): string
Generates a random encryption key.
-
Parameters:
int $length: The desired length of the encryption key in bytes. Valid lengths are 16, 32, or 64 bytes. Defaults to 32 bytes.
-
Returns: The generated random encryption key, represented as a hexadecimal string.
-
Throws: An exception if the length is not valid.
generateSalt(int $length = 16): string
Generates a random salt.
-
Parameters:
int $length: The desired length of the salt in bytes. Valid lengths are 16, 32, or 64 bytes. Defaults to 16 bytes.
-
Returns: The generated random salt, represented as a hexadecimal string.
-
Throws: An exception if the length is not valid.
Usage
To use the Encrypter Bundle in your Symfony application, you can inject the EncrypterInterface into your services or controllers. Here's an example of how you can encrypt and decrypt data:
use ManojX\EncrypterBundle\EncrypterInterface; class YourService { private EncrypterInterface $encrypter; public function __construct(EncrypterInterface $encrypter) { $this->encrypter = $encrypter; } public function encryptData(string $data): string { $salt = 'your-salt'; // Define your salt return $this->encrypter->encrypt($data, $salt); } public function decryptData(string $encryptedData): string { $salt = 'your-salt'; // Use the same salt for decryption return $this->encrypter->decrypt($encryptedData, $salt); } }
manojx/encrypter-bundle 适用场景与选型建议
manojx/encrypter-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 804 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「bundle」 「encryption」 「decryption」 「encrypter」 「aes-256-cbc」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 manojx/encrypter-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 manojx/encrypter-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 manojx/encrypter-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
2lenet/EasyAdminPlusBundle
The bundle for easy using json-rpc api on your project
A simple PHP class to encrypt a string and decrypt an encrypted string
A package for automatically encrypting and decrypting Eloquent attributes in Laravel 5.5+, based on configuration settings.
Provide a way to secure accesses to all routes of an symfony application.
Encryption with AES-256 and HMAC-SHA256
统计信息
- 总下载量: 804
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 23
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-10-05