Cryptographically Secure Database & Application Key Engine
Save a complete backup of your database tables before performing any key rotation operations.
Use the provided PHP / Node key rotation script to decrypt existing records using your Old Key and re-encrypt them with your New Key.
Once data re-encryption completes, update ENCRYPTION_KEY in your .env file with the new key.
<?php
// Load old key and new key
$oldKey = 'base64:OLD_KEY_HERE';
$newKey = 'base64:NEW_KEY_HERE';
// Fetch database records, decrypt with $oldKey, encrypt with $newKey, update database.
// See rotate-keys.php in workspace directory for complete executable script.
You can generate keys directly inside your terminal using any of the following pre-built CLI scripts or shell commands:
php -r "echo 'base64:' . base64_encode(random_bytes(32)) . PHP_EOL;"
php -r "echo 'hex:' . bin2hex(random_bytes(32)) . PHP_EOL;"
php generate-keys.php
node generate-keys.js
./generate-keys.sh
Follow these step-by-step instructions to safely apply generated keys to your website and application server.
Navigate to the root directory of your website on your server or local machine (e.g. /public_html, /var/www/html/site, or project folder). Look for the hidden .env file.
.env does not exist yet, copy .env.example to .env. In Linux/macOS, use ls -a to view hidden dotfiles.
Open .env in a text editor (VS Code, Nano, Sublime, or cPanel File Manager) and update the corresponding key values:
# Security & Master Encryption Keys
APP_KEY=base64:YOUR_GENERATED_APP_KEY
ENCRYPTION_KEY=base64:YOUR_GENERATED_ENCRYPTION_KEY
MASTER_KEY_512=base64:YOUR_GENERATED_512_BIT_KEY
SEARCH_KEY=base64:YOUR_GENERATED_SEARCH_KEY
BACKUP_KEY=base64:YOUR_GENERATED_BACKUP_KEY
# HMAC & Token Secrets
QR_HMAC_SECRET=hex:YOUR_GENERATED_HEX_SECRET
JWT_SECRET=YOUR_GENERATED_JWT_SECRET
After editing your .env file, notify your application web server to load the new keys:
php artisan config:clear and php artisan config:cache in your terminal.pm2 restart all or restart your node server).sudo systemctl restart gunicorn).You can manage and regenerate keys in this dashboard anytime using these 3 actions:
Click the top-right header button to regenerate a completely new set of 256-bit and 512-bit keys across all cards at once.
Click the 🔄 refresh icon on any specific key card to change only that single key without altering others.
Go to the .env File Export tab and click "Download .env File" to get a ready-to-use file instantly.
Below is the complete terminal walkthrough showing exact shell commands and expected outputs at each step:
cd /Users/faldutarang4778gmail.com/Desktop/"NEW WEBSITE" && ls -la
total 128
drwxr-xr-x 16 staff 512 Aug 26 03:30 .
drwxr-xr-x 6 staff 192 Aug 26 03:20 ..
-rw-r--r-- 1 staff 480 Aug 26 03:25 .env
-rw-r--r-- 1 staff 1080 Aug 26 03:20 package.json
drwxr-xr-x 12 staff 384 Aug 26 03:22 public
php generate-keys.php
==========================================================
DATABASE & SECURITY KEY GENERATOR (Cryptographically Secure)
==========================================================
ENCRYPTION_KEY : base64:NbCQhFkWcSqwZsPvv57kJEor9rJLBCQdXEVjCwCSUBM=
SEARCH_KEY : base64:YHmmPF6K4UKUSkYphu60K4uNGl8yQOlor/ahjnmlBqE=
BACKUP_KEY : base64:bXb3UE0eYBq4z0eB0Qr34OGarutE9hNgxv/VqYX6IOc=
APP_KEY : base64:pAxkDCHIhdlCbP3riv9AEGc++XL1U/cZVsvhl+dTRw4=
QR_HMAC_SECRET : hex:492150678fa672dfcd2a4774a4c7facfe2971a9e2cef704f3180a648d1d57b9c
DB_PASSWORD : K#8x$mQ9!zP2vL5wN4@bT7yU0*eR3c1f
JWT_SECRET : 5059dea1cec3916f4760c05b975a1e837cbafc4729846c0c59a99c9ef8999c23
nano .env
GNU nano 7.2 .env
APP_ENV=production
APP_DEBUG=false
APP_KEY=base64:pAxkDCHIhdlCbP3riv9AEGc++XL1U/cZVsvhl+dTRw4=
ENCRYPTION_KEY=base64:NbCQhFkWcSqwZsPvv57kJEor9rJLBCQdXEVjCwCSUBM=
SEARCH_KEY=base64:YHmmPF6K4UKUSkYphu60K4uNGl8yQOlor/ahjnmlBqE=
BACKUP_KEY=base64:bXb3UE0eYBq4z0eB0Qr34OGarutE9hNgxv/VqYX6IOc=
QR_HMAC_SECRET=hex:492150678fa672dfcd2a4774a4c7facfe2971a9e2cef704f3180a648d1d57b9c
JWT_SECRET=5059dea1cec3916f4760c05b975a1e837cbafc4729846c0c59a99c9ef8999c23
[ Press Ctrl+O then Enter to Save, Ctrl+X to Exit ]
php artisan config:clear && php artisan config:cache
INFO Configuration cache cleared successfully.
INFO Configuration cached successfully.