Skip to content

Instantly share code, notes, and snippets.

@alex-alekseichuk
Last active December 2, 2023 14:27
Show Gist options
  • Save alex-alekseichuk/57089c230bcaa739899d3183f04472da to your computer and use it in GitHub Desktop.
Save alex-alekseichuk/57089c230bcaa739899d3183f04472da to your computer and use it in GitHub Desktop.
Edit encrypted by password text file
#!/usr/bin/bash
echo -n 'Password: '
read -s password
plain=$(mktemp)
openssl enc -aes-256-cbc -pbkdf2 -iter 100000 -pass pass:$password -d <$1 >$plain 2>/dev/null
prev=$(mktemp)
cp $plain $prev
vi $plain
if ! (cmp -s $prev $plain); then
openssl enc -aes-256-cbc -pbkdf2 -iter 100000 -pass pass:$password <$plain >$1 2>/dev/null
fi
rm -rf $plain
rm -rf $prev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment