I'm not completely sure I understand what you want, but I think something like the following should work:
$ echo -ne "$(echo -n "message" | sha1sum | cut -f1 -d" " | sed -e 's/\(.\{2\}\)/\\x\1/g')" | base64
Basically, I take the hex output, use sed
to make it a string of escaped hex values, and then use echo -en
to echo the bytes into base64
.
We can confirm that the final output corresponds to the same hash with the following exercise:
$ echo -n "message" | sha1sum
6f9b9af3cd6e8b8a73c2cdced37fe9f59226e27d -
$ echo -ne "$(echo -n "message" | sha1sum | cut -f1 -d" " | sed -e 's/\(.\{2\}\)/\\x\1/g')" | base64
b5ua881ui4pzws3O03/p9ZIm4n0=
$ echo -n "b5ua881ui4pzws3O03/p9ZIm4n0=" | base64 -d | xxd
0000000: 6f9b 9af3 cd6e 8b8a 73c2 cdce d37f e9f5 o....n..s.......
0000010: 9226 e27d .&.}
Visual inspection shows that our base64 value matches the original hex. Note that if you use hexdump
rather than xxd
you may have to play with the format settings a bit to get the output you expect.