I need to execute hmac openssl, but when change a parameter I have a strange behaviour.
With these values, HMAC works properly
$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -hmac `printf 71ef1c30a1a5503dd387aac85b714b779c7df8bc163b1fad66b1d51c94cd221e|xxd -r -p` | awk '{print $2}'
71af33b003e7e8033fcec8ad2ef46ee22b6518ae072fae24708201542d1b01bbe0b67fce1733443bfaddd52307e28fbe4e3c0945be31853d8f1caeb078dfc220
When change the value 71ef1c30a1a5503dd387aac85b714b779c7df8bc163b1fad66b1d51c94cd221e with a new value 2C31FBB2B809A9B2252FE64EC6D0011A8EAAA4D0A72EEEDF0A1E1DCF1B514320 I get an error
$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -hmac `printf 2C31FBB2B809A9B2252FE64EC6D0011A8EAAA4D0A72EEEDF0A1E1DCF1B514320 |xxd -r -p` | awk '{print $2}'
%/NЧ.: No such file or directory
C: No such file or directory
UPDATE
I tried with -macopt
first result is the same
$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -mac HMAC -macopt key:`printf 71ef1c30a1a5503dd387aac85b714b779c7df8bc163b1fad66b1d51c94cd221e|xxd -r -p`
(stdin)= 71af33b003e7e8033fcec8ad2ef46ee22b6518ae072fae24708201542d1b01bbe0b67fce1733443bfaddd52307e28fbe4e3c0945be31853d8f1caeb078dfc220
Second result same issue
$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -mac HMAC -macopt key:`printf 2C31FBB2B809A9B2252FE64EC6D0011A8EAAA4D0A72EEEDF0A1E1DCF1B514320|xxd -r -p`
??%/?N?????Ч.??: No such file or directory
?C: No such file or directory
Try with double quotes
$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -hmac "`printf 71ef1c30a1a5503dd387aac85b714b779c7df8bc163b1fad66b1d51c94cd221e|xxd -r -p`" | awk '{print $2}'
71af33b003e7e8033fcec8ad2ef46ee22b6518ae072fae24708201542d1b01bbe0b67fce1733443bfaddd52307e28fbe4e3c0945be31853d8f1caeb078dfc220
$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -hmac "`printf 2C31FBB2B809A9B2252FE64EC6D0011A8EAAA4D0A72EEEDF0A1E1DCF1B514320 |xxd -r -p`" | awk '{print $2}'
3b63439866b95de9d5402688dd26162fdd25646262087bebdffe024c5136954ea34a8f908de1b523ebf3fa86813db6a098d153ac79a8905e520134799fec8247
Related
I'm trying to compile the U-boot 2020.07 with option CONFIG_USE_DEFAULT_ENV_FILE=y and with the path to file which contains new U-boot environments records.
u-boot-suniv-spiflash/1_v2020.07-r0/git/scripts/Makefile.build
obj=scripts/basic | /bin/sh: 1: xxd: not found
I try to compile manually the same U-boot with the same Yocto toolchain and the compilation success U-boot works with replaced env records.
The problem is related to Makefile. I found somewhere some solution which allows me to compile success but with empty environment records in U-boot after boot-up.
The problematic syntax is
define filechk_defaultenv.h
(grep -v '^#' | \
grep -v '^$$' | \
tr '\n' '\0' | \
sed -e 's/\\\x0\s*//g' | \
xxd -i ; echo ", 0x00" ; )
ended
the solution from internet is
define filechk_defaultenv.h
(grep -v '^#' | \
grep -v '^$$' | \
tr '\n' '\0' | \
sed -e 's/\\\x0\s*//g' | \
xxd -i | \
sed -r 's/([0-9a-f])$$/\1, /'; \
echo "0x00" ; )
ended
Unfortunately, these environment records are empty after U-Boot's start-up.
Do You have knowledge of what am I doing wrong?
The following command works for SHA1: csum -h SHA1 (FileName).txt > (FileName_chksum).txt. How to create a similar file using the SHA256 algorithm in AIX?
You can use the openssl command from the openssl.base package; it has a dgst sub-command that will generate a SHA256 hash of the file:
openssl dgst -sha256 filename.txt > filename_sha256.txt
By default, it will print in the following format:
SHA256(filename.txt)= hash-string-here
The csum command prints in a slightly different format:
hash-string-here filename.txt
... so you may want to rearrange the output of openssl based on your specific needs for the filename_sha256.txt file.
If you only want the hashed string itself in the new file, you could use awk:
openssl dgst -sha256 filename.txt | awk '{print $2}' > filename_sha256.txt
When I try to SHA512 some file using openssl I got the output file contents starts with something like "SHA512(in.txt)= 090c..."
I tried the different options -r, -binary with the command
Here is the command I'm using
openssl dgst -sha512 -out out.txt in.txt
The question is: How can I got the file contains only the hash, without that starting note?
You can only print the second column using awk, if the file name doesn't contain spaces:
openssl dgst -sha512 -out in.txt | awk '{print $2}' > out.txt
Or (looks like not cross-platform) you can try either pipe or reading from stdin:
openssl dgst -sha512 -out out.txt < in.txt
cat in.txt | openssl dgst -sha512 -out out.txt
This works for me (Mac OS X).
The default delimiter of awk is a space character, and the accepted answer will not work if there are spaces in the filename. You can override the default delimiter with the -F flag (field separator) to = , but that would also not work if there happens to be an equal space in the filename. Printing the last column using the default delimiter should work for all of those edge cases. The $NF awk variable stores the number of fields and can be used directly to print the last column, which should always be the hash.
openssl dgst -sha512 -out in.txt | awk '{print $NF}' > out.txt
https://linux.die.net/man/1/awk
I know we can get the right output in below ways:
echo -n 123456 | openssl md5
e10adc3949ba59abbe56e057f20f883e
or
printf 123456 | openssl md5
e10adc3949ba59abbe56e057f20f883e
or
printf 123456 > file.txt
openssl md5 file.txt
e10adc3949ba59abbe56e057f20f883e
However, I want to know could we work it out in below command-line with extra options
openssl md5 <<< '123456'
f447b20a7fcbf53a5d5be013ea0b15af( this is incorrect)
bash (and ksh93, and zsh) will always append a newline to the content of the here-string. There is no way around this apart from filtering it out explicitly.
$ tr -d '\n' <<<'123456' | openssl md5
(stdin)= e10adc3949ba59abbe56e057f20f883e
I have a script2:
# This is script2 that is called by script1.
CURRENT_TOMCAT_PROCESS=`ps -ef | grep java | grep $TOMCAT_USER | grep -v grep | awk '{print $2}'`
echo "---> $CURRENT_TOMCAT_PROCESS"
and I call script2 in script1:
ssh $user#$server 'bash -s' < script2
It works fine. But I'm having trouble make the backtick work in a HERE document:
ssh $user#$server 'bash -s' <<EOF
CURRENT_TOMCAT_PROCESS=`ps -ef | grep java | grep $TOMCAT_USER | grep -v grep | awk '{print \$2}'`
echo "---> $CURRENT_TOMCAT_PROCESS"
EOF
(If I don't assign it to a variable and just print it out it works fine, but when I try to assign it to CURRENT_TOMCAT_PROCESS variable using backticks, it doesn't work.)
How can I make this work?
Thanks,
===============================================================================
I could make it work the following way. There are lots of escaping involved:
ssh $user#$server 'bash -s' <<EOF
CURRENT_TOMCAT_PROCESS="\`ps -ef | grep java | grep $TOMCAT_USER | grep -v grep | awk '{print \$2}'\`"
echo "---> \$CURRENT_TOMCAT_PROCESS"
EFO
I think it is reasonable to escape, because you want to transfer the '$' to remote site. You seems make a typo on your last result. I tried to type here again
TOMCATE_USER=foo
ssh $user#$server 'bash -s' <<EOF
CURRENT_TOMCAT_PROCESS="\`ps -ef | grep java | grep $TOMCAT_USER | grep -v grep | awk '{print \$2}'\`"
echo "---> \$CURRENT_TOMCAT_PROCESS"
EOF