PHPackages                             bgeneto/ci4-secrets - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. bgeneto/ci4-secrets

ActiveLibrary[Templating &amp; Views](/categories/templating)

bgeneto/ci4-secrets
===================

Secrets ackage for Codeigniter 4 framework

v1.0.2(1y ago)08PHPPHP ^7.4 || ^8.0

Since Feb 11Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bgeneto/ci4-secrets)[ Packagist](https://packagist.org/packages/bgeneto/ci4-secrets)[ Docs](https://github.com/bgeneto/ci4-secrets)[ RSS](/packages/bgeneto-ci4-secrets/feed)WikiDiscussions main Synced today

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

CI4 Secrets
===========

[](#ci4-secrets)

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-installation)

---

### 1.1 Composer + Packagist

[](#11-composer--packagist)

```
composer require bgeneto/ci4-secrets
```

### 1.2 Composer + GitHub:

[](#12-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:

[](#13-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

[](#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

[](#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

[](#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-usage)

---

### 2.1 CLI Usage

[](#21-cli-usage)

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

#### Available Operations

[](#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

[](#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

[](#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
-------------------

[](#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
-------

[](#license)

This package is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance40

Moderate activity, may be stable

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

506d ago

PHP version history (2 changes)v1.0.1PHP &gt;=8.0

v1.0.2PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/473074?v=4)[Bernhard Enders](/maintainers/bgeneto)[@bgeneto](https://github.com/bgeneto)

---

Top Contributors

[![bgeneto](https://avatars.githubusercontent.com/u/473074?v=4)](https://github.com/bgeneto "bgeneto (19 commits)")

---

Tags

phphtmlcodeignitermodelviewcontrollersecretscodeigniter4

###  Code Quality

Static AnalysisPsalm

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bgeneto-ci4-secrets/health.svg)

```
[![Health](https://phpackages.com/badges/bgeneto-ci4-secrets/health.svg)](https://phpackages.com/packages/bgeneto-ci4-secrets)
```

###  Alternatives

[daycry/twig

twig for Codeigniter 4

155.5k2](/packages/daycry-twig)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
