Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

openssl input in hexadecimal for bash

How do we input value and key as hexadecimal values?

echo -n "value" | openssl dgst -sha1 -hmac "key"
$value=11111111FFAA2211
$key=11111111FFAA2211000000000011BBFF
echo -n "$value" | openssl dgst -sha1 -hmac "$key"

is not working either.

like image 553
Ursa Major Avatar asked May 12 '26 21:05

Ursa Major


1 Answers

I just managed to solved it, it's the use of the '-macopt hexkey:string' option.

echo -n '4869205468657265' | xxd -r -p | openssl dgst -sha512 -mac HMAC -macopt hexkey:0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b

(stdin)= 87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854

or

key='0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b' value='4869205468657265' echo -n "$value" | xxd -r -p | openssl dgst -sha512 -mac HMAC -macopt hexkey:$key

(stdin)= 87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854

I hope this answer may serve as a mini tutorial to help people.

like image 166
Ursa Major Avatar answered May 15 '26 10:05

Ursa Major