Skip to content

Instantly share code, notes, and snippets.

@hobroker
Created January 7, 2023 20:06
Show Gist options
  • Save hobroker/b5bf4e05b55bd1ae1f95876dfc846d42 to your computer and use it in GitHub Desktop.
Save hobroker/b5bf4e05b55bd1ae1f95876dfc846d42 to your computer and use it in GitHub Desktop.
Create/edit/encrypt/decrypt a file with a password
#!/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