承接 bgeneto/ci4-secrets 相关项目开发

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

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

bgeneto/ci4-secrets

Composer 安装命令:

composer require bgeneto/ci4-secrets

包简介

Secrets ackage for Codeigniter 4 framework

README 文档

README

CI4 Secrets is a CodeIgniter 4 package designed to provide a secure and reliable way to store sensitive data, such as API keys, certificate passwords, and other confidential information. By utilizing CI4's encryption key, CI4 Secrets encrypts data at rest and stores it securely using your default database connection.

With CI4 Secrets, you can eliminate the risk of storing sensitive information in plain text within your .env file, reducing the exposure of your application to potential security breaches. Instead, store your secrets securely and access them easily through the package's intuitive interface.

1. Installation

1.1 Composer + Packagist

composer require bgeneto/ci4-secrets

1.2 Composer + GitHub:

Just setup the repository like this in your project's composer.json file:

{
    "require": {
        "your-project/other-dependencies": "...",
        "bgeneto/ci4-secrets": "dev-main"
    },

    "repositories": {
        "sanitize": {
            "type": "vcs",
            "url": "https://github.com/bgeneto/ci4-secrets.git"
        }
    }
}

1.3 Composer + Local:

git clone https://github.com/bgeneto/ci4-secrets.git /path/to/your/local/ci4-secrets

Now edit your composer.json file and add a new repository:

{
    "require": {
        "your-project/other-dependencies": "...",
        "bgeneto/ci4-secrets": "dev-main"
    },

    "repositories": {
        "sanitize": {
            "type": "path",
            "url": "/path/to/your/local/ci4-secrets"
        }
    }
}

2. Check if you have an encryption key

Check in your .env or in Config\Encryption if you have an encryption key already configured, if not just run this spark command below:

php spark key:generate

This will put a encryption key in your .env similar to this:

encryption.key = hex2bin:2869d5b48952d4268d1cf5fb37d24e6850875fd86f246f959a7c315718d039a2

3. Publish the package config file

php spark secrets:publish

This will create a new Config\Secrets.php file that you can customize.

5. Create the required table

This packages uses only one database table called secrets . You have to run the spark migration command to create it.

php spark migrate --all

2. Usage

2.1 CLI Usage

The Secrets package provides the following spark new command: php spark secrets with the available options:

Available Operations

  • add: Add a new secret.
  • update: Update an existing secret.
  • delete: Delete a secret.
  • list: List all secret keys.
  • get: Get a secret value.

Usage Examples

# Add a new secret via interactive mode:
php spark secrets add

# Add a new secret directly using its name (key) and value:
php spark secrets add --key=api_key --value=sk_12345678

# Force add if key exists
php spark secrets add --key=api_key --value=sk_12345678 --force=yes

# Update an existing secret
php spark secrets update --key=api_key --value=sk-87654321

# Update interactively
php spark secrets update

# Delete a secret with inline parameter
php spark secrets delete --key=api_key

# Or delete in interactive mode
php spark secrets delete

# List all secrets
php spark secrets list

# Get a secret value
php spark secrets get

## Get help
php spark secrets

The Secrets library provides methods to securely store, encrypt, and decrypt sensitive data using CodeIgniter 4's encryption service anywhere (model, controllers...).

use Bgeneto\Secrets\Secrets;

$secrets = new secrets();
$secrets->store('new_secret', 'new_secret_value');

// OR simply
$secrets = Services::secrets();
$secrets->retrieve('new_secret');

Methods

  • encrypt(string $data): string
  • decrypt(string $encryptedData): string
  • store(string $key, string $value, bool $log = true): bool
  • update(string $key, string $value, bool $log = true): bool
  • retrieve(string $key, bool $log = true): ?string
  • delete(string $key, bool $log = true): bool

There is also a model class (Bgeneto\Secrets\Models\BaseSecretModel) that you can extend in order to add new features like logging/auditing.

Extending the Model

You can extend the BaseSecretModel to add custom functionality, such as using traits with model callbacks. To do this:

  1. Create a custom model: Create a new model class that extends Bgeneto\Secrets\Models\BaseSecretModel. For example:

    // app/Models/SecretModel.php
    namespace App\Models;
    
    use Bgeneto\Secrets\Models\BaseSecretModel;
    
    class SecretModel extends BaseSecretModel
    {
        // Add your custom traits and methods here
        use \App\Traits\MyTrait; // Example
    }
  2. Update the configuration: Modify the modelClass option in Config/Secrets.php to point to your custom model:

        /**
         * The model class to use for managing secrets.
         *
         * @var string
         */
        public $modelClass = '\App\Models\SecretModel';

By following these steps, the Secrets class will use your custom model, allowing you to leverage traits and their associated callbacks.

License

This package is licensed under the MIT License. See the LICENSE file for details.

bgeneto/ci4-secrets 适用场景与选型建议

bgeneto/ci4-secrets 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 02 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「view」 「controller」 「html」 「codeigniter」 「model」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 bgeneto/ci4-secrets 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 bgeneto/ci4-secrets 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 11
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-02-11