Encrypt-Decrypt Properties Script:
This script provides a way to encrypt and decrypt .properties
files using the Age encryption tool. It ensures secure handling of sensitive files with minimal manual intervention and integrates seamlessly into various workflows.
- Age Tool: The script depends on the Age tool for encryption and decryption.
- Bash Shell: This script is designed to work on Unix-like systems, including macOS and Linux.
-
Install Age Tool:
-
On macOS:
- Install using Homebrew:
brew install age
- Install using Homebrew:
-
On Linux:
- Download the latest release from the Age GitHub Releases.
- Extract the downloaded
.tar.gz
archive:tar -xzf age-vX.Y.Z-linux-amd64.tar.gz
- Move
age
andage-keygen
binaries to/usr/local/bin
:sudo mv age age-keygen /usr/local/bin
-
Verify installation by checking the versions:
age --version age-keygen --version
-
-
Generate Encryption Key:
-
Generate a new key file using
age-keygen
:age-keygen > key.txt
Important Note: The
key.txt
file contains your private key starting withAGE-SECRET-KEY-
. Keep this file secure and private.
-
-
Retrieve the Public Key:
- The public key, or "recipient key," can be derived from
key.txt
. - It will look like
age1...
and be listed after# public key
. - Make sure to replace it, otherwise you will get error with recepient key.
- The public key, or "recipient key," can be derived from
-
Replace
RECIPIENT_KEY
:- In the provided script, replace the
RECIPIENT_KEY
variable with your public key derived fromkey.txt
.RECIPIENT_KEY="age1yourderivedpublickey"
- In the provided script, replace the
-
Make Script Executable:
- Ensure the script file has executable permissions.
chmod +x EncryptDecryptProperties.sh
- Ensure the script file has executable permissions.
-
Encrypting Files:
- Run the script with the encrypt argument to encrypt all .properties files:
All
./EncryptDecryptProperties.sh encrypt
.properties
files will be encrypted and given the.age
extension.
- Run the script with the encrypt argument to encrypt all .properties files:
-
Decrypting Files:
- Run the script with the decrypt argument to decrypt all .age files:
All decrypted files will be restored to their original
./EncryptDecryptProperties.sh decrypt
.properties
format.
- Run the script with the decrypt argument to decrypt all .age files: