HMAC openssl 的奇怪行为

Strange behaviour with HMAC openssl

我需要执行 hmac openssl,但是当更改参数时我有一个奇怪的行为。

使用这些值,HMAC 可以正常工作

$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -hmac `printf 71ef1c30a1a5503dd387aac85b714b779c7df8bc163b1fad66b1d51c94cd221e|xxd -r -p` | awk '{print }'
71af33b003e7e8033fcec8ad2ef46ee22b6518ae072fae24708201542d1b01bbe0b67fce1733443bfaddd52307e28fbe4e3c0945be31853d8f1caeb078dfc220

当用新值 71ef1c30a1a5503dd387aac85b714b779c7df8bc163b1fad66b1d51c94cd221e 更改值 2C31FBB2B809A9B2252FE64EC6D0011A8EAAA4D0A72EEEDF0A1E1DCF1B514320 时出现错误

$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -hmac `printf 2C31FBB2B809A9B2252FE64EC6D0011A8EAAA4D0A72EEEDF0A1E1DCF1B514320 |xxd -r -p` | awk '{print }'
%/NЧ.: No such file or directory
C: No such file or directory

更新 我试过 -macopt

第一个结果相同

$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -mac HMAC -macopt key:`printf 71ef1c30a1a5503dd387aac85b714b779c7df8bc163b1fad66b1d51c94cd221e|xxd -r -p`   
(stdin)= 71af33b003e7e8033fcec8ad2ef46ee22b6518ae072fae24708201542d1b01bbe0b67fce1733443bfaddd52307e28fbe4e3c0945be31853d8f1caeb078dfc220

第二个结果相同

$ 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

试试用双引号

$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -hmac "`printf 71ef1c30a1a5503dd387aac85b714b779c7df8bc163b1fad66b1d51c94cd221e|xxd -r -p`" | awk '{print }'
71af33b003e7e8033fcec8ad2ef46ee22b6518ae072fae24708201542d1b01bbe0b67fce1733443bfaddd52307e28fbe4e3c0945be31853d8f1caeb078dfc220

$ printf 03d4f7e460787295bb803f7f9fa3c023b3cb33623aadbea53720decfa5a4f6005800000000 |xxd -r -p | openssl dgst -sha512 -hmac "`printf 2C31FBB2B809A9B2252FE64EC6D0011A8EAAA4D0A72EEEDF0A1E1DCF1B514320 |xxd -r -p`" | awk '{print }'
3b63439866b95de9d5402688dd26162fdd25646262087bebdffe024c5136954ea34a8f908de1b523ebf3fa86813db6a098d153ac79a8905e520134799fec8247