AES-CBC incorrect usage - encryption

I am trying to do AES-CBC cipher and decipher via openssl, however, I am not able to get the correct output. Please advise me. Thank you.
cipher
clr;
MSG_CIPHERED_HEX="920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a"
IV="00000000000000000000000000000000"
KEY="00000000000000000000000000000000"
echo -n "$MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -aes-128-cbc -K $KEY -iv $IV | xxd -p | tr -d '\n'
decipher
clr;
MSG_CIPHERED_HEX="734563526574204d6553734167452030300a0e0e0e0e0e0e0e0e0e0e0e0e0e0e"
echo $MSG_CIPHERED_HEX
MSG_ASCII=echo $MSG_HEX | xxd -p -r | tr -d '\n'; echo $MSG_ASCII > tmp.ciphered.file.ascii;
openssl enc -d -aes-128-cbc -K $KEY -iv $IV -in tmp.ciphered.file.ascii -out out.txt
cat out.txt | xxd -p # | tr -d '\n'
rm -rf tmp.ciphered.file.ascii out.txt
There seemed to be data formatting issue:
$ #decipher
MSG_CIPHERED_HEX="920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a" IV="00000000000000000000000000000000" KEY="00000000000000000000000000000000" echo -n "$MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -d -aes-128-cbc -K $KEY -iv $IV | xxd -p | tr -d '\n'
Ans:
734563526574204d6553734167452030300a (truncated)
$ #cipher
MSG_CIPHERED_HEX="920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a" IV="00000000000000000000000000000000" KEY="00000000000000000000000000000000" echo -n "$MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -aes-128-cbc -K $KEY -iv $IV | xxd -p | tr -d '\n'
Ans:
236999001256bd4131dffa3417c29bfc597a43f6bde387ba0e42da86e67cfff42890e4f6e84c0e70753a9db754df996e

The e0e0e0e0e0e0e0e0e0e0e0e0e0e is 14 bytes of padding. If you specify padding on decryption it will be automatically removed.
See PKCS7 padding.

Related

How to decode openssl enc'd data with salted password?

$ curl -s 'https://finance.yahoo.com/quote/MSFT/profile?p=MSFT' | awk -v ORS= 'match($0, /^ *root[.]App[.]main = (.*);$/, a) { print a[1] }' | jq -r .context.dispatcher.stores > /tmp/tmp.txt
$ file /tmp/tmp.txt
/tmp/tmp.txt: openssl enc'd data with salted password, base64 encoded
How can I decode the above data?

How to decrypt a large AES encrypted data with openssl command?

I want to decrypt large AES encrypted data:
Encrypted data: 7dS560FiDJvUji7c+ky/9nQp+HwK3SEOkY4zefqlFuEyF2/vevrv8K4GJNr2zxD7+j28RK97LmaHjwY9F+/feO6T2DAQuJQsT3wp/fKCPyErwZggsE+ufzvEJZK/XObR8CdbBe8EGZC//JsuMo7MV6SSe267jp4U2iIz4xIFxUlFVy9QcjTr6AUJZdVogedreBgy3/q/isAqOvwoHuj74MV5gkfaXWvmqESjMF4s5wMsYmS1WuBWOR6rw+TSwuL52CiVC5arHuJJEKuodO58bJ+1Ip9uelUIOETswiZmZB6gpTkbos7ij0BpJregejT+9vsDO1tB7+QpByMqeeEbEiSp4N833Z29WmVmy+HpxdZvOPIJ2pyelVhRVPPs/V7VREs4v8/e3X1jR0saA1sSyKYNgIGZUWaQTJwBNi87IPkGiUtyhPnrrKh+BighshJi+Jd+s3+sTYM5CaADvaGhm3wx96rBQi2So+NmFcm5cQa4jRA4S8sLGHmniUO0iiEcxQ2FvlGt+0PBqdbCPewBgOHdjpBUYjs1oR4pV5VjbjTfuIh75G7TS6TZT/gMewJXOXPw88zsSgjXVjRK0obOXaJBKABJ8AqKbKULWHoeMuWW4OdiSZ7mNVt6N40LK/u12vpqWU7Wt5XbSeE3arJPjljEV7WhafKvIOHFx+cK0wB9LQnFUrx/FTLL5HDDEkhnVkm02vxXSFKDwP36VgQnPpvOnY5fbJUTyjnwJcO8I9/H1hYwzPRhos2eNAdHZ3aMysU8zSobwUVto9GnQrvVmVURFyEX6fwifkrf2DTfCsDNSsHt4DLCtsszABKTwTezUoBesNkndk/Qkcd13GEZjTHoyP2tLp85nYwbwI6P+yr1jeu9v3ocN5p0LWPXdwlyTo55WeYkGzlJLsM6d9sut1qlcyQ2AZ536+eYFAIURJkmSexwfbdRebwckvqURRO3a55WCbLxVARKDHnyfculr/ndwyZF7J0RX4G1KcwSgfRdnBpUCkpGeQRImv5Ry5RYXwp5XfKQDrGTCEhV3XtDBD4b2eTxw4KwgJUq9T6IQjNNyPyDwM5AFxS2Y+4wAA0PA2iADfVe3kZrOKYpZvVn0Q== (base64 encoded)
Key: uHe2MCmggLlugpGBiMVuXTck7OT8Nk8g (base64 encoded)
Cipher: AES-256-CBC
IV: LNP8U7pc6GjxzxAtgw4s3A== (base64 encoded)
I try to use this command for it:
openssl aes-256-cbc -d -in data.enc -out data.dec -K $key -iv $iv
In $key and $iv i decoded from encoded values this way
iv=$( cat response.json | jq .iv -r | openssl base64 -d | xxd -p | tr -d '\n' )
But i have crashed data like this
^GÌ<8a>û)F"PEi~^K±jÔ^AcWSM
23NDwSOqovXSFGNfy3WatkCreYRd7kcWSM";

unix script run search in parallel

I have a script that searches files for a phrase in a number of different folders, then shows to output.
The trouble is, it does each search sequentially and takes a long time. I would like to make the searches run without waiting for the previous one to finish.
zipped_folders=("/extlogs/archive/rsyslog/folder1/"
"/extlogs/archive/rsyslog/folder2/")
folders=("/extlogs/rsyslog/Folder1/"
"/extlogs/rsyslog/Folder2/")
portal=0
mobile=0
email=0
if [ "$#" -ne 1 ]; then
echo "Incorrect Argument: logcount 201602"
exit 1
fi
for i in "${zipped_folders[#]}"
do
#echo $i"syslog-"$1*".log.gz"
((portal+=$(nohup gunzip -c $i"syslog-"$1*".log.gz" | grep -i "search1" | grep -v "Search1" | wc -l &)))
((mobile+=$(nohup gunzip -c $i"syslog-"$1*".log.gz" | grep -i "Search2" | wc -l &)))
((email+=$(nohup gunzip -c $i"syslog-"$1*".log.gz" | grep -i "search3" | grep -v "ActiveSync" | wc -l &)))
done
for i in "${folders[#]}"
do
((portal+=$(nohup cat $i"syslog-"$1*".log"| grep -i "search4"| grep -v "exsearch4" | wc -l &)))
((mobile+=$(nohup cat $i"syslog-"$1*".log" | grep -i "search5" | wc -l &)))
((email+=$(nohup cat $i"syslog-"$1*".log" | grep -i "search6" | grep -v "ActiveSync" | wc -l &)))
done
echo "Portal: " $portal
echo "Mobile: " $mobile
echo "Email: " $email
exit 1
You can use xargs.
find ${topdir} -name '*.gz' | xargs -n1 -P${PARALLEL_JOBS} -I {} bash -c "/usr/bin/grep 'criteria' {}"

how to improve the below space issue coding

while i ran the below script it returns nothing... expect the prompt as the output..
#!/bin/sh
cd /dla
op=`df -k /dla/ |awk '{print $5}' |grep '%' |cut -d '%' -f1`
if[ $op -ge 80 ]
then
echo ' dla is more tha 80% - Purge started'
find /dla/ -name '20[0-9][0-9]*' -type d -print |sort |cut -d '/' -f7 |grep 20 | sort | uniq -c |head -20 > /tmp/file_list.dat
for i in cat /tmp/file_list.dat |awk '{print $#}'
do
find /dla -name $i -type d -exec rm -rf [] \;
newop='df -k /dla/ |awk '{print $5}' |grep '%' |cut -d '%' -f1'
if [$newop -le 80]
then
echo 'dla is 80% -Purge stopped'
exit 0
fi
done
else
echo 'dla is less than 80% - No Purge Required'
fi

Error while running command from cron (tcsh)

When I'm running this command from shell(tcsh), it executes perfectly-
cal | tail -6 | sed -e 's/^.\{3\}//' -e 's/.\{3\}$//' | tr -s '[:blank:]' '\n' | head -21 | tail -20 | tr -s '\n' ' ' | grep -w `date "+%e"` ; /usr/bin/bash -lc "if [ "$?" == 0 ] ; then echo xyz ; fi"
But when I put the exact same thing in a crontab, I get this error mail from my machine-
Subject: Output from "cron" command
Content-Length: 244
Your "cron" job on uatserver
cal | tail -6 | sed -e 's/^.\{3\}//' -e 's/.\{3\}$//' | tr -s '[:blank:]' '\n' | head -21 | tail -20 | tr -s '\n' ' ' | grep -w `date "+
produced the following output:
Usage: grep -hblcnsviw pattern file . . .
I'm sure that even my crontab commands are executed using tcsh as it is set to be the default.
p.s- My machine:
SunOS uatserver 5.10 Generic_127112-11 i86pc i386 i86pc
Your problem is that the PATH variable is not the same. Solaris has different flavors of grep
examples:
/usr/bin/grep
/usr/xpg4/bin/grep
You crontab ran /usr/bin/grep instead of /usr/xpg4/bin/grep. The two versions of grep have some different options.

Resources