Skip to content

Generating Security Keys

Arthu Santiago edited this page Nov 30, 2026 · 1 revision

Generating Security Keys

KeyAnyWhere needs three secrets, all generated by you and never copied from an example. This page explains what each one protects, what happens if it changes or leaks, and how to generate it. In the production path, the next page (Environment Variables) generates all three for you while it creates the environment file; come back here when you need to understand or replace one of them.

The three secrets

Each secret has a different job, and losing each one has a different cost. Read this table before deciding where to keep the copies.

Variable What it protects If it changes If it leaks
KEY_CRIPTOGRAFIC Encrypts every stored title, username, password, link, note, category name and 2FA secret (libsodium secretbox). Every stored secret becomes unreadable. There is no recovery and no re-encryption tool. Never change it on a running installation. Whoever also has a copy of the database can decrypt everything.
SECURITY_SALT Signs cookies and CSRF tokens (CakePHP Security.salt). At least 32 characters, or the application refuses to start. Users are logged out and their CSRF cookies are renewed on the next page they open. Nothing is lost. Cookies can be forged. Replace it.
CONFIG_INICIAL_TOKEN Opens the first-run setup, which creates the administrator. At least 32 characters. Only matters before the setup is done. Only matters before the setup is done. After that, you can delete it.

Warning

Keep a copy of KEY_CRIPTOGRAFIC outside the server, in a place that does not depend on KeyAnyWhere itself (a different password manager, a printed copy in a safe). A database backup is useless without it. See Backup and Restore.

Generating a secret by hand

Use these commands to generate a single secret, for example to replace a leaked SECURITY_SALT. Each one prints a new random value.

KEY_CRIPTOGRAFIC (64 hexadecimal characters, a libsodium key):

php -r 'echo sodium_bin2hex(sodium_crypto_secretbox_keygen()), PHP_EOL;'

SECURITY_SALT (64 hexadecimal characters):

php -r 'echo bin2hex(random_bytes(32)), PHP_EOL;'

CONFIG_INICIAL_TOKEN (64 hexadecimal characters):

php -r 'echo bin2hex(random_bytes(32)), PHP_EOL;'

To replace a value in production, edit it in /etc/keyanywhere/keyanywhere.env and restart Apache:

sudoedit /etc/keyanywhere/keyanywhere.env
sudo systemctl restart apache2

Next step

Environment Variables

Clone this wiki locally