Skip to content

Instantly share code, notes, and snippets.

@edthrn
Last active August 30, 2025 11:08
Show Gist options
  • Save edthrn/a4985d841a0ec63fdee8d7aa258702ee to your computer and use it in GitHub Desktop.
Save edthrn/a4985d841a0ec63fdee8d7aa258702ee to your computer and use it in GitHub Desktop.
AES encryption/decryption using openssl
#!/bin/bash
function encrypt {
input=$1
echo "Encrypting $input..."
openssl enc -aes-256-cbc -pbkdf2 -iter 800000 -in "$input" -out cipher.bin
echo "Encrypted file saved to: $(pwd)/cypher.bin"
}
function decrypt {
input=$1
echo "Decrypting $input..."
openssl enc -d -aes-256-cbc -pbkdf2 -iter 800000 -in "$input" -out plain.txt
echo "Decrypted file saved to: $(pwd)/plain.txt"
}
if [ "$#" -ne 2 ]; then
echo "Usage: $0 [encrypt|decrypt] [input_file]"
exit 1
fi
action=$1
input_file=$2
case "$action" in
encrypt)
encrypt "$input_file"
;;
decrypt)
decrypt "$input_file"
;;
*)
echo "Invalid action. Use 'encrypt' or 'decrypt'."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment