Download the PHP package bgeneto/ci4-secrets without Composer
On this page you can find all versions of the php package bgeneto/ci4-secrets. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bgeneto/ci4-secrets
More information about bgeneto/ci4-secrets
Files in bgeneto/ci4-secrets
Package ci4-secrets
Short Description Secrets ackage for Codeigniter 4 framework
License
Homepage https://github.com/bgeneto/ci4-secrets
Informations about the package 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.1 Composer + Packagist
1.2 Composer + GitHub:
Just setup the repository like this in your project's composer.json
file:
1.3 Composer + Local:
Now edit your composer.json
file and add a new repository:
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:
This will put a encryption key in your .env
similar to this:
3. Publish the package config file
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.
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
The Secrets
library provides methods to securely store, encrypt, and decrypt sensitive data using CodeIgniter 4's encryption service anywhere (model, controllers...).
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:
-
Create a custom model: Create a new model class that extends
Bgeneto\Secrets\Models\BaseSecretModel
. For example: - Update the configuration: Modify the
modelClass
option inConfig/Secrets.php
to point to your custom model:
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.