A simple bash script that allows you to securely edit encrypted files. The script supports file creation, decryption, editing using your preferred editor, and re-encryption with the same password.
- Encrypt and decrypt files using OpenSSL with AES-256-CBC and PBKDF2 for strong password-based encryption.
- Supports editing files with
$EDITOR
or falls back tonano
if$EDITOR
is not set. - Automatically handles temporary files securely, ensuring sensitive data is not left on disk.
- Bash: The script is designed to run on Unix-like systems.
- OpenSSL: Ensure OpenSSL is installed on your system. Use
openssl version
to verify. - Text Editor: Any text editor (e.g.,
nano
,vim
,nvim
,emacs
). The script defaults tonano
if no editor is specified in the$EDITOR
environment variable.
- Clone the repository:
git clone https://github.com/yourusername/encrypted-file-editor.git
cd encrypted-file-editor
- Make the script executable:
chmod +x edit_encrypted_file.sh
- Optionally, move it to a directory in your
PATH
for global access:
sudo mv edit_encrypted_file.sh /usr/local/bin/encrypt-edit
The script takes one argument, the name of the encrypted file. It decrypts the file, allows you to edit it, and re-encrypts it with the same password.
./encr <encrypted_file>
./encr my_secret_file.enc
- Prompts for the password to decrypt the file.
- Opens the decrypted file in your text editor (e.g.,
$EDITOR
ornano
). - Re-encrypts the file after editing using the same password.
./encr new_file.enc
- If the file doesn’t exist, it creates an empty file for editing.
- Prompts for a password to encrypt the new file.
- Saves and encrypts the file after editing.
$EDITOR
: Specifies the text editor to use. Defaults tonano
if not set.
To set a default editor (e.g., vim
):
export EDITOR="vim"
- Uses AES-256-CBC cipher with PBKDF2 for strong encryption.
- Securely handles passwords without storing them in plaintext.
- Cleans up temporary files after use.
- OpenSSL: Used for encryption and decryption.
- The script uses a single password for both decryption and encryption. Make sure to remember the password, as there is no recovery mechanism.