PHPackages                             kanti/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. [Security](/categories/security)
4. /
5. kanti/secrets

ActiveLibrary[Security](/categories/security)

kanti/secrets
=============

Allows to commit encrypted Secrets

1.0.0(1y ago)14PHPPHP ^8.2CI failing

Since Feb 12Pushed 1y ago1 watchersCompare

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

READMEChangelog (1)Dependencies (1)Versions (6)Used By (0)

Kanti Secrets
=============

[](#kanti-secrets)

This is a little library to allow to commit any Secret without exposing it to the public.
the secrets will be encrypted inside the code.

> !!! the secrets will be stored as plaintext in a ksk-cache.json file on disk. (for performance reasons)

Installation
------------

[](#installation)

```
composer require kanti/secrets
```

Usage
-----

[](#usage)

### in code

[](#in-code)

to encrypt a secret you can use the `Secrets::convert()` method.

```
use Kanti\Secrets\Secrets;

# prerequisite: you need to have a .env file with a KSK_KEY set and It must be loaded in your code
$databasePassword = Secrets::convert('topSecretPassword');
# after first run of this code the code will have change to:
$databasePassword = Secrets::decrypt('7boUYdo8crSe1DsMDZbqG67vcvLxIOhEys1-9Rz-KUfzwX2k5ei5DhC2Wjt1qUzHK2N_pwqsrVO2VSEa');
```

```
use Kanti\Secrets\Secrets;
# you can define the location of the ksk-cache.json file like this:
Secrets::setCacheFile('/path/to/ksk-cache.json');
```

### generate a secret

[](#generate-a-secret)

```
# this will generate a new secret and store it in the .env file (if not already present)
./vendor/bin/ksk

# Outputs something like this:
Key already set in /app/.env file
KSK_KEY=ksk-yI1YRuVxsp1jJH7KcU3t2tignYmI2O_PLKqy2flBHzs1XBXudSLwf-lhryOV-qA4Rv0YchDb2jk
╔════════════════════ ═══ ══ ═  ═
║ Found usage:
║ File: /app/sync.php:25
║ value: "t34vctngh3840vngtc803m5b8t0gm2b4m29x4,nr94n,"
║ // load dotenv
║
║ dd([
║     'password2' => Secrets::decrypt('7boUYdo8crSe1DsMDZbqG67vcvLxIOhEys1-9Rz-KUfzwX2k5ei5DhC2Wjt1qUzHK2N_pwqsrVO2VSEa'),  Secrets::decrypt('JSeg-Q6xMKJ52UUsLNQY766zNqThMeVRx4pmp03jIgD3wzbnoer-CA'),
║     'password' => Secrets::decrypt('d0Fcuh2UcsMJe-j7ELUGKaq9NfflO_RH'),
║ ]);
╚════════════════════ ═══ ══ ═  ═
╔════════════════════ ═══ ══ ═  ═
║ Found usage:
║ File: /app/sync.php:26
║ value: "top secret fake password"
║
║ dd([
║     'password2' => Secrets::decrypt('7boUYdo8crSe1DsMDZbqG67vcvLxIOhEys1-9Rz-KUfzwX2k5ei5DhC2Wjt1qUzHK2N_pwqsrVO2VSEa'),
║     'top' => Secrets::decrypt('JSeg-Q6xMKJ52UUsLNQY766zNqThMeVRx4pmp03jIgD3wzbnoer-CA'),  Secrets::decrypt('d0Fcuh2UcsMJe-j7ELUGKaq9NfflO_RH'),
║ ]);
║
╚════════════════════ ═══ ══ ═  ═
╔════════════════════ ═══ ══ ═  ═
║ Found usage:
║ File: /app/sync.php:27
║ value: "password"
║ dd([
║     'password2' => Secrets::decrypt('7boUYdo8crSe1DsMDZbqG67vcvLxIOhEys1-9Rz-KUfzwX2k5ei5DhC2Wjt1qUzHK2N_pwqsrVO2VSEa'),
║     'top' => Secrets::decrypt('JSeg-Q6xMKJ52UUsLNQY766zNqThMeVRx4pmp03jIgD3wzbnoer-CA'),
║     'password' => Secrets::decrypt('d0Fcuh2UcsMJe-j7ELUGKaq9NfflO_RH'),
