Created
September 29, 2024 06:16
-
-
Save robertsinfosec/ac78b20b89c3bce81a7d4100b513d01c to your computer and use it in GitHub Desktop.
Bash support for quick AES-256 encryption/decryption with a prompted password. Add to the end of your `~/.bashrc`
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
# Other .bashrc contents here... | |
encrypt() { | |
# Read password from /dev/tty | |
echo -n "Enter password: " > /dev/tty | |
read -s PASSWORD < /dev/tty | |
echo > /dev/tty | |
if [ -t 0 ]; then | |
INPUT="$*" | |
else | |
INPUT=$(cat) | |
fi | |
echo -n "$INPUT" | openssl enc -aes-256-cbc -pbkdf2 -iter 10000 -md sha512 -pass pass:"$PASSWORD" | base64 --wrap=0 | |
echo "" | |
} | |
decrypt() { | |
# Read password from /dev/tty | |
echo -n "Enter password: " > /dev/tty | |
read -s PASSWORD < /dev/tty | |
echo > /dev/tty | |
if [ -t 0 ]; then | |
# If no input is piped, use the arguments | |
INPUT="$*" | |
else | |
# If input is piped, read from stdin | |
INPUT=$(cat) | |
fi | |
echo -n "$INPUT" | base64 --decode | openssl enc -d -aes-256-cbc -pbkdf2 -iter 10000 -md sha512 -pass pass:"$PASSWORD" | |
echo "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment