OpenSSL does not match Python hashlib -
OpenSSL does not match Python hashlib -
i new using openssl library , cannot output match output python's crypto libraries. below example.
python code:
import hmac secret = "asdf1234" string = '{"request"}' hmac.new(secret, string, hashlib.sha384).hexdigest() '92904f1b3c210a4fb19f476c19f24452717e85329aa9ffaba4a5fbe1111c2e3fa7f5a5fb35fdc58b3d158f5f886c3d02'
openssl:
echo -n {"request"} | openssl dgst -sha384 -hmac asdf1234 -hex (stdin)= 4c3d525b8a7095b9063a3bd974e56f0a5872399365912297d6ee18e400d2b55d0142395ba5fb4f33655ceca209ba9570
what doing wrong? either implementation correct?
to match openssl output, python string should '{request}'
rather '{"request"}'
.
import hmac import hashlib secret = "asdf1234" string = '{request}' hmac.new(secret, string, hashlib.sha384).hexdigest()
yields
'4c3d525b8a7095b9063a3bd974e56f0a5872399365912297d6ee18e400d2b55d0142395ba5fb4f33655ceca209ba9570'
or, if want openssl command match python output, use
echo -n '{"request"}' | openssl dgst -sha384 -hmac asdf1234 -hex
which yields
(stdin)= 92904f1b3c210a4fb19f476c19f24452717e85329aa9ffaba4a5fbe1111c2e3fa7f5a5fb35fdc58b3d158f5f886c3d02
after all, inputs have match outputs have chance @ matching:
% echo -n {"request"} {request}
and
>>> print('{"request"}') {"request"}
python openssl sha pyopenssl
Comments
Post a Comment