$ 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?
I'm trying too encrypt and decrypt using pkcs#11-tool
echo 'Hello word !' | openssl pkeyutl -encrypt -pubin \
-inkey pub.pem \
-pkeyopt rsa_padding_mode:oaep \
-pkeyopt rsa_oaep_md:sha512 \
-pkeyopt rsa_mgf1_md:sha512 \
-out encrypted.data
This work find but trying to decrypt it fail
pkcs11-tool --module /usr/local/lib/softhsm/libsofthsm2.so --decrypt \
--mechanism RSA-PKCS-OAEP \
--input-file encrypted.data \
--label keyp \
--hash-algorithm SHA512 --pin Jojo
I'm having this error :
Using slot 0 with a present token (0x607f2e7f)
Using decrypt algorithm RSA-PKCS-OAEP
OAEP parameters: hashAlg=SHA512, mgf=MGF1-SHA512, source_type=0, source_ptr=(nil), source_len=0
error: PKCS11 function C_DecryptInit failed: rv = CKR_ARGUMENTS_BAD (0x7)
Aborting.
I'm following this tutorial : https://docs.nitrokey.com/nethsm/guides/pkcs11_with_pkcs11-tool and can't what wrong.
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";
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.
How can I send an email through the UNIX mailx command?
an example
$ echo "something" | mailx -s "subject" recipient#somewhere.com
to send attachment
$ uuencode file file | mailx -s "subject" recipient#somewhere.com
and to send attachment AND write the message body
$ (echo "something\n" ; uuencode file file) | mailx -s "subject" recipient#somewhere.com
Here you are :
echo "Body" | mailx -r "FROM_EMAIL" -s "SUBJECT" "To_EMAIL"
PS. Body and subject should be kept within double quotes.
Remove quotes from FROM_EMAIL and To_EMAIL while substituting email addresses.
mailx -s "subjec_of_mail" abc#domail.com < file_name
through mailx utility we can send a file from unix to mail server.
here in above code we can see
first parameter is -s "subject of mail"
the second parameter is mail ID and the last parameter is name of file which we want to attach
mail [-s subject] [-c ccaddress] [-b bccaddress] toaddress
-c and -b are optional.
-s : Specify subject;if subject contains spaces, use quotes.
-c : Send carbon copies to list of users seperated by comma.
-b : Send blind carbon copies to list of users seperated by comma.
Hope my answer clarifies your doubt.
Its faster with MUTT command
echo "Body Of the Email" | mutt -a "File_Attachment.csv" -s "Daily Report for $(date)" -c cc_mail#g.com to_mail#g.com -y
-c email cc list
-s subject list
-y to send the mail
From the man page:
Sending mail
To send a message to one or more people, mailx can be invoked with
arguments which are the names of
people to whom the mail will be sent.
The user is then expected to type in
his message, followed
by an ‘control-D’ at the beginning of a line.
In other words, mailx reads the content to send from standard input and can be redirected to like normal. E.g.:
ls -l $HOME | mailx -s "The content of my home directory" someone#email.adr
echo "Sending emails ..."
NOW=$(date +"%F %H:%M")
echo $NOW " Running service" >> open_files.log
header=`echo "Service Restarting: " $NOW`
mail -s "$header" abc.xyz#google.com, \
cde.mno#yahoo.com, \ < open_files.log
Customizing FROM address
MESSAGE="SOME MESSAGE"
SUBJECT="SOME SUBJECT"
TOADDR="u#u.com"
FROM="DONOTREPLY"
echo $MESSAGE | mail -s "$SUBJECT" $TOADDR -- -f $FROM
Here is a multifunctional function to tackle mail sending with several attachments:
enviaremail() {
values=$(echo "$#" | tr -d '\n')
listargs=()
listargs+=($values)
heirloom-mailx $( attachment=""
for (( a = 5; a < ${#listargs[#]}; a++ )); do
attachment=$(echo "-a ${listargs[a]} ")
echo "${attachment}"
done) -v -s "${titulo}" \
-S smtp-use-starttls \
-S ssl-verify=ignore \
-S smtp-auth=login \
-S smtp=smtp://$1 \
-S from="${2}" \
-S smtp-auth-user=$3 \
-S smtp-auth-password=$4 \
-S ssl-verify=ignore \
$5 < ${cuerpo}
}
function call:
enviaremail "smtp.mailserver:port" "from_address" "authuser" "'pass'" "destination" "list of attachments separated by space"
Note: Remove the double quotes in the call
In addition please remember to define externally the $titulo (subject) and $cuerpo (body) of the email prior to using the function
If you want to send more than two person or DL :
echo "Message Body" | mailx -s "Message Title" -r sender#someone.com receiver1#someone.com,receiver_dl#.com
here:
-s = subject or mail title
-r = sender mail or DL