6

I need to base64 encode a binary sha1 hash. What is the best way to do this? I imagine this would involve piping binary data into base64. Unfortunately sha1sum does not have a binary output option. Any ideas?

This is what I need to do:

echo mydata|sha1sum --binary-output|base64

sha1sum does not have a --binary-output option though.

  • 3
    How did binary creep into this? – tink May 30 '13 at 23:32
  • 1
    I believe that jcalfee314 is saying that he wants to base64 encode an actual SHA1 hash value, rather than the hex representation thereof that the sha1 program outputs. – Scott May 30 '13 at 23:47
3

Try converting hex to base64. This answer is one option. There are a number of other implementations.

How can I convert from hex to base64?

| improve this answer | |
1

Maybe something like:

echo mydata | sha1sum | xxd -r -p | base64

... would solve your problem.

See https://unix.stackexchange.com/questions/82561/convert-a-hex-string-to-binary-and-send-with-netcat for similar question.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.