LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-06-2020, 11:10 AM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Rep: Reputation: 56
Decrypt encrypted message with wrong password and have no error output.


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

Last edited by ddenial; 08-06-2020 at 11:12 AM.
 
Old 08-06-2020, 02:24 PM   #2
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
If I could at least disable this stupid error message with symbols all over my terminal when given with the wrong password, I can make some improvements in my script.

Code:
[neon@fed ~/Documents]$ openssl aes-256-cbc -a -d -salt -pbkdf2 -in secret.txt 2>/dev/null
enter aes-256-cbc decryption password: aaaa
-�)�3;#^;��^$ ���
,�e�U9b5_�> ��.p�O$_@��>�/���8ަ2�xؿl�ä����M��/;ȇ�6퐙d%�Pn8F����plw�&c"'ݎ�CB����}�M�p�:�[neon@fed ~/Documents]$
Can anyone throw some lights on how to disable this horrible output error from displaying when a wrong password is given? I tried all I/O redirection I can think of in my limited understanding to no avail.

Thanks.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Decrypt encrypted LibreOffice documents with known password Michael Uplawski Linux - Software 0 09-24-2019 01:05 AM
mutt unable to decrypt emails "Could not decrypt PGP message" frddbbbl Linux - Software 3 07-25-2019 10:48 AM
Ubuntu 12.04 hard drive encrypted and the existing password cannot decrypt it... andrew262 Ubuntu 2 05-22-2014 07:24 AM
Ubuntu 12.04 hard drive was encrypted and the existing password cannot decrypt it... andrew262 Linux - Newbie 2 05-15-2014 01:23 PM
Tool to decrypt old encrypted harddrive and backup data before reformat bapigoo9 Linux - Software 5 12-02-2008 01:32 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:54 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration