Last active
July 12, 2022 14:05
-
-
Save marius-m/6b99a20c9512bb5e7da99fee6ae9cc1f to your computer and use it in GitHub Desktop.
SH script that uses `openssl` to decrypt raw text input to aes-sha256-cbc + base64 (Check crypt.sh for inverse function)
This file contains 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
#!/bin/bash | |
# Decrypts input file (+base64) contents with AES-256-CBC and a password | |
#set -x | |
FILE_IN=$1 | |
if [[ -f $FILE_IN ]]; then | |
echo "Converting..." | |
else | |
echo "File not found!" | |
exit 1 | |
fi | |
#KEY_PASS="pass1" | |
KEY_PASS="k7hlmq6sst2qz5yg2cl3bg1yyj1y5zge" | |
KEY_PASS_DIGEST="$(echo -n $KEY_PASS | openssl sha256)" | |
KEY_PASS_DIGEST_B64="$(echo -n $KEY_PASS_DIGEST | base64)" | |
FILE_NOEXT=$(basename "$FILE_IN" | cut -d. -f1) | |
FILE_OUT="${FILE_NOEXT}.txt.dec" | |
## Original | |
echo "==(original)==> ${FILE_IN}" | |
echo -e "------------------------\n" | |
cat ${FILE_IN} | |
echo -e "\n------------------------\n" | |
## Decrypt | |
# @param "-a" decodes input directly from b64 | |
# @param "-d" decode mode | |
openssl aes-256-cbc -nosalt -d -a -A \ | |
-in ${FILE_IN} -out ${FILE_OUT} \ | |
-iv "0000000000000000" \ | |
-K "${KEY_PASS_DIGEST}" | |
echo "$FILE_IN =(dec: aes256: \"$KEY_PASS\" + b64)> ${FILE_OUT}" | |
echo -e "------------------------\n" | |
cat ${FILE_OUT} | |
echo -e "\n------------------------\n" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment