Created
January 7, 2023 20:06
-
-
Save hobroker/b5bf4e05b55bd1ae1f95876dfc846d42 to your computer and use it in GitHub Desktop.
Create/edit/encrypt/decrypt a file with a password
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
FILE=$1 | |
FILE_ENC="$FILE.enc" | |
encrypt() { | |
openssl enc -aes-256-cbc -e -in "$FILE" -out "$FILE_ENC" -pass "pass:$PASS" | |
} | |
decrypt() { | |
openssl enc -aes-256-cbc -d -in "$FILE_ENC" -out "$FILE" -pass "pass:$PASS" | |
} | |
remove() { | |
rm "$FILE" | |
} | |
edit() { | |
nano "$FILE" | |
} | |
printf 'Password: ' | |
read -s PASS | |
echo "" | |
if [ ! -f "$FILE_ENC" ] | |
then | |
echo "File does not exist" | |
sleep 0.5 | |
touch "$FILE" | |
encrypt | |
fi | |
decrypt && edit && encrypt && remove |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment