nzo/url-encryptor-bundle
Composer 安装命令:
composer require nzo/url-encryptor-bundle
包简介
The NzoUrlEncryptorBundle is a Symfony Bundle used to Encrypt and Decrypt data and variables in the Web application or passed through URL
README 文档
README
The NzoUrlEncryptorBundle is a Symfony Bundle used to Encrypt and Decrypt data and variables in the Web application or passed through the URL to provide more security to the project.
Also it prevent users from reading and modifying sensitive data sent through the URL.
The Version (^6.0) is compatible with Symfony >= 4.4
Features include:
- Url Data & parameters Encryption
- Url Data & parameters Decryption
- Data Encryption & Decryption
- Access from Twig by ease
- Flexible configuration
- Uses OpenSSL extension
By default, this bundle use the aes-256-ctr algorithm.
CTR mode (without any additional authentication step) is malleable, which means that it is possible to change the meaning of the ciphertext and if the plaintext is guessable then it could lead to IDOR.
For more secure output, you must configure the bundle to use a unique and random IV (random_pseudo_bytes: TRUE)
Installation
Through Composer:
Install the bundle:
$ composer require nzo/url-encryptor-bundle
Register the bundle in config/bundles.php (without Flex):
// config/bundles.php return [ // ... Nzo\UrlEncryptorBundle\NzoUrlEncryptorBundle::class => ['all' => true], ];
Configure the bundle:
# config/packages/nzo_encryptor.yaml nzo_encryptor: secret_key: Your_Secret_Encryption_Key # Required, max length of 100 characters. secret_iv: Your_Secret_Iv # Required only if "random_pseudo_bytes" is FALSE. Max length of 100 characters. cipher_algorithm: # optional, default: 'aes-256-ctr' base64_encode: # optional, default: TRUE format_base64_output: # optional, default: TRUE, used only when 'base64_encode' is set to TRUE random_pseudo_bytes: # optional, default: TRUE (generate a random encrypted text output each time => MORE SECURE !)
* To generate the same cypher text each time: random_pseudo_bytes: FALSE (Not Secure)
* To generate a different cypher text each time: random_pseudo_bytes: TRUE (Secure)
Usage
In the twig template:
Use the twig extensions filters or functions to encrypt or decrypt your data:
// Filters:
# Encryption:
<a href="{{path('my-route', {'id': myId | nzo_encrypt } )}}"> My link </a>
{{myVar | nzo_encrypt }}
# Decryption:
<a href="{{path('my-route', {'id': myId | nzo_decrypt } )}}"> My link </a>
{{myVar | nzo_decrypt }}
// Functions:
# Encryption:
<a href="{{path('my-path-in-the-routing', {'id': nzo_encrypt('myId') } )}}"> My link </a>
{{ nzo_encrypt(myVar) }}
# Decryption:
<a href="{{path('my-path-in-the-routing', {'id': nzo_decrypt('myId') } )}}"> My link </a>
{{ nzo_decrypt(myVar) }}
In the controller with annotation service:
Use the annotation service to decrypt / encrypt automatically any parameter you want, by using the ParamDecryptor / ParamEncryptor annotation service and specifying in it all the parameters to be decrypted/encrypted.
use Nzo\UrlEncryptorBundle\Annotations\ParamDecryptor; use Nzo\UrlEncryptorBundle\Annotations\ParamEncryptor; class MyController { /** * @ParamDecryptor({"id", "foo"}) */ // OR #[ParamDecryptor(["id", "foo"])] public function decryptionAction($id, $foo) { // no need to use the decryption service here as the parameters are already decrypted by the annotation service. //... } /** * @ParamEncryptor({"id", "foo"}) */ // OR #[ParamEncryptor(["id", "foo"])] public function encryptionAction($id, $foo) { // no need to use the encryption service here as the parameters are already encrypted by the annotation service. //... } }
With autowiring:
use Nzo\UrlEncryptorBundle\Encryptor\Encryptor; class MyController { private $encryptor; public function __construct(Encryptor $encryptor) { $this->encryptor = $encryptor; } public function indexAction($data) { $encrypted = $this->encryptor->encrypt($data); $decrypted = $this->encryptor->decrypt($data); } }
Without autowiring:
class MyController { public function indexAction($data) { $encrypted = $this->get('nzo_encryptor')->encrypt($data); $decrypted = $this->get('nzo_encryptor')->decrypt($data); } }
License
This bundle is under the MIT license. See the complete license in the bundle:
See LICENSE
nzo/url-encryptor-bundle 适用场景与选型建议
nzo/url-encryptor-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.09M 次下载、GitHub Stars 达 95, 最近一次更新时间为 2013 年 09 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「data」 「security」 「url」 「link」 「encryption」 「id」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 nzo/url-encryptor-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nzo/url-encryptor-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 nzo/url-encryptor-bundle 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Shoot aims to make providing data to your templates more manageable
Adds the EDTF data type to Wikibase
A simple library that allows transform any kind of data to native php data or whatever
Provide a way to secure accesses to all routes of an symfony application.
Easy URL rewrites in your Laravel application
It's a barebone security class written on PHP
统计信息
- 总下载量: 1.09M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 97
- 点击次数: 36
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-09-25