linux - Compute base64 encoded hash from a given hash? -
i created file , input random string it.
touch tesseract && echo 'testtesttesttesttest' > tesseract
now if use openssl
compute base64
hash [sha256
], run this:
cat tesseract | openssl dgst -sha256 | openssl base64 -a
which returns me
khn0zglukt0gmzjjyja1mtgzndnhzmy2n2flmmy5yzuwndcwngringe5njc5mziyzwvlntbmmjbintmznjzlytbimdy2mwnlzgo=
now process hash stepwise, as,
cat tesseract | openssl dgst -sha256 > partialhash
which gives me
(stdin)= 32cb0518343aff67ae2f9c504704db4a9679322eee50f20b53366ea0b0661cef
let hash x
. this,
echo '32cb0518343aff67ae2f9c504704db4a9679322eee50f20b53366ea0b0661cef' > partialhash cat partialhash | openssl base64 -a
i different result. why that?
my reason asking because use binary, hashdeep
gives me hashes in form of 32cb0518343aff67ae2f9c504704db4a9679322eee50f20b53366ea0b0661cef
, wish convert them base64
encoded format hashdeep
not capable of producing base64
output. pipe intermediate hash openssl base64 -a
, obtain different result.
what missing? how can convert non-encoded hash x
[which 32cb0518343aff67ae2f9c504704db4a9679322eee50f20b53366ea0b0661cef
] proper base64
encoded format?
for simplicity purpose, can assume x
present in file,
created using echo '32cb0518343aff67ae2f9c504704db4a9679322eee50f20b53366ea0b0661cef' > file
you're not base-64 encoding hash. you're base64-encoding string
(stdin)= 32cb0518343aff67ae2f9c504704db4a9679322eee50f20b53366ea0b0661cef
(followed newline). note (stdin)=
@ beginning. that's part of string. that's going have different value base64 encoding of string 32cb0518343aff67ae2f9c504704db4a9679322eee50f20b53366ea0b0661cef
(followed newline).
if goal binary hashes (rather string encodings), use -binary
option openssl dgst
.
i'm not familiar hashdeep
, when "non-encoded hash," that's not it's generating. it's generating hex-encoded hash. looks of you're looking hex-to-base64 converter. can along these lines:
echo '32cb0518343aff67ae2f9c504704db4a9679322eee50f20b53366ea0b0661cef' | xxd -r -p | base64
xxd -r -p
converts hex-encoded string raw data.
(if you're using openssl dgst
, make sure you're using options don't inject (stdin)=
on front. version of openssl doesn't this, i'm not flag you'll need.)
Comments
Post a Comment