nzo/url-encryptor-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

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

tests Total Downloads Latest Stable Version

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 我们能提供哪些服务?
定制开发 / 二次开发

基于 nzo/url-encryptor-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.09M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 97
  • 点击次数: 36
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 95
  • Watchers: 5
  • Forks: 19
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-09-25