Hello All
I have some encrypted text in my shell script. I want to decrypt it on-the-fly from within shell script provided the correct password.
If the correct password is provided, then display message. But if the wrong password is given, just echo the 'Wrong password' message and exit shell script.
These are the steps I followed.
Code:
$ cat cleartext.txt
This is a very important secret message for authorized eyes only:
"Why Did the Chicken Cross the Road?"
Burn After Reading.
$ openssl aes-256-cbc -a -salt -pbkdf2 -in cleartext.txt -out secret.txt
$ cat secret.txt
U2FsdGVkX18KYDskEKxri/xwUQ0m7Svp5UrlFs5wjVqrLVOwfpFIHa2cu3Sl+l6M
eQ2SdNyg2j3KzWOqMNu83cX5LS+HWvs5kPKQKL3j+qiI3ucUElVNc0JfG59y8+tn
3WMMDpb5JD+I9T5vMWz5E7OA658M0xkgMng0WYNtXBFeBOk8K1caSkFNuRHmUfef
NOGNukvVmHJ4gvdcRoQjJg==
Now I put this in my script:
Code:
$ cat showmsg.sh
#!/bin/bash
MSG() {
cat <<EOF
U2FsdGVkX18KYDskEKxri/xwUQ0m7Svp5UrlFs5wjVqrLVOwfpFIHa2cu3Sl+l6M
eQ2SdNyg2j3KzWOqMNu83cX5LS+HWvs5kPKQKL3j+qiI3ucUElVNc0JfG59y8+tn
3WMMDpb5JD+I9T5vMWz5E7OA658M0xkgMng0WYNtXBFeBOk8K1caSkFNuRHmUfef
NOGNukvVmHJ4gvdcRoQjJg==
EOF
}
# Store decrypted tags in variable. Needs password.
VAR=$(MSG | openssl aes-256-cbc -a -d -salt -pbkdf2 2>/dev/null)
if [[ $? -eq 0 ]] ; then
echo
echo -e ">>> And The Message Is <<<"
echo "${VAR}"
echo
echo "And do some othe stuff for later"
else
echo "Wrong password! Exiting..."
exit 1
fi
Now, if I give correct password 'abcd', then the message will be display properly. But if I give wrong password, say 'aaaa', I get some error message. Why?
Code:
$ ./showmsg.sh
enter aes-256-cbc decryption password: abcd
>>> And The Message Is <<<
This is a very important secret message for authorized eyes only:
"Why Did the Chicken Cross the Road?"
Burn After Reading.
And do some othe stuff for later
$ ./showmsg.sh
enter aes-256-cbc decryption password: aaaa
./showmsg.sh: line 13: warning: command substitution: ignored null byte in input
Wrong password! Exiting...
What is this '
command substitution: ignored null byte in input' error? How do I solve this?
Thanks