env-secure
v1.0.0
Published
A CLI tool to securely encrypt and decrypt .env files.
Downloads
4
Readme
env-secure
env-secure is a powerful command-line utility designed to safeguard your .env files by encrypting sensitive environment variables using AES-256 encryption. With env-secure, you can ensure that your secret keys, API keys, and other sensitive data are securely stored and only accessible to authorized users. The tool also supports key rotation, allowing you to update your encryption key without compromising security. Whether you're working locally or in a team, env-secure provides a simple and secure way to manage your environment variables.
Table of Contents
Installation
To install env-secure, you need to have Node.js installed on your system. Once Node.js is installed, run the following command:
npm install -g env-secureThis will install env-secure globally, allowing you to use it from any directory.
Usage
Overview of the commands:
flowchart TD
env-secure[env-secure] -->|can be used to initialize the secret key| set-key(env-secure set-key)
env-secure[env-secure] -->|can be used to encrypt the .env file| encrypt(env-secure encrypt)
env-secure[env-secure] -->|can be used to decrypt the .env file| decrypt(env-secure decrypt)
env-secure[env-secure] -->|can be used to change the secret key value| rotate-key(env-secure rotate-key)Set the Secret Key:
Before encrypting or decrypting your .env file, you need to set a secret key. This key is used for encryption and decryption.
env-secure set-keyYou will be prompted to enter a secret key. This key will be saved in your .env file under the ENV_SECURE_KEY variable.
Example:
$ env-secure set-key
Enter your secret key: my-secret-key
Secret key saved successfully.Encrypt a .env File:
To encrypt your .env file, run the following command:
env-secure encryptYou will be prompted to enter a passphrase. This passphrase is used to encrypt the secret key, ensuring that no part of the .env.enc file is stored in plain text.
Example:
$ env-secure encrypt
Enter your passphrase: my-passphrase
Successfully encrypted .env to .env.enc.This will create an encrypted .env.enc file and delete the original .env file.
Decrypt a .env.enc File:
To decrypt your .env.enc file, run the following command:
env-secure decryptYou will be prompted to enter the passphrase you used during encryption. If the passphrase is correct, the .env.enc file will be decrypted, and the original .env file will be restored.
Example:
$ env-secure decrypt
Enter your passphrase: my-passphrase
Successfully decrypted .env.enc to .env.Rotate the Secret Key:
To rotate the secret key, run the following command:
env-secure rotate-keyYou will be prompted to:
Enter your current secret key.
Enter your new secret key.
Example:
$ env-secure rotate-key
Enter your current secret key: my-secret-key
Enter your new secret key: my-new-secret-key
Secret key updated successfully.This will update the secret key in the .env file. No encryption or decryption is performed during rotation.
Security Considerations
Secret Key:
The secret key is used for encrypting and decrypting your .env file. Keep it secure and do not share it.
If the secret key is compromised, rotate it immediately using the rotate-key command.
Passphrase:
The passphrase is used to encrypt the secret key. Choose a strong passphrase and do not share it.
If the passphrase is forgotten, the .env.enc file cannot be decrypted.
Encrypted File:
The .env.enc file contains no plain text. All data, including the secret key, is encrypted.
Store the .env.enc file securely and do not share it.
Backup:
- Always keep a backup of your original .env file before encrypting it.
How It Works
Encryption Process
The secret key is encrypted using a passphrase-derived key.
The encrypted secret key is stored in the
.env.encfile as the first line.The rest of the
.envfile is encrypted using the secret key.The original
.envfile is deleted after encryption.
Decryption Process
The encrypted secret key is extracted from the
.env.encfile.The secret key is decrypted using the passphrase-derived key.
The rest of the
.env.encfile is decrypted using the secret key.The original
.envfile is restored, and the.env.encfile is deleted.
Rotation Process
The secret key in the
.envfile is updated.No encryption or decryption is performed during rotation.
Contributing
Contributions are welcome! If you find a bug or have a feature request, please open an issue on the GitHub repository.
To contribute code:
Fork the repository.
Create a new branch for your feature or bug fix.
Submit a pull request.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Support
If you have any questions or need help, please open an issue on the GitHub repository or contact me through Email.
