Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am on Mac OS X 10.8.2, running a compiled copy of xxd v1.10 (source code) as well as the copy of xxd that comes preinstalled on OS X.

I am trying to generate a Base64-encoded SHA1 signature via a chain of piped commands in Terminal.

Normally I would do something like the following:

$ echo "foo" | openssl sha1 | xxd -p -r | base64 - > foo_sha1_signature

The file foo_sha1_signature normally contains a Base64-encoded SHA1 hash of the string foo.

The problem is that xxd -p -r does not return any data, so the file foo_sha1_signature is empty.

If I split the commands up to look at the output from xxd -r, I get a result (as printed below):

$ echo "foo" | openssl sha1 | xxd -p | xxd -r
7b36c94bcdf32bee$

But if I pipe standard output to a file, the file is empty:

$ echo "foo" | openssl sha1 | xxd -p | xxd -r > foo_sha1_bytes
$ ls -al foo_sha1_bytes 
-rw-r--r--  1 alexpreynolds  staff  0 Jan  2 23:02 foo_sha1_bytes

If I try piping standard error, the standard output shows the bytes and the file is still empty:

$ echo "foo" | openssl sha1 | xxd -p | xxd -r 2> foo_sha1_bytes
7b36c94bcdf32bee$

Finally, if I do all this on Linux, xxd works as expected (I get the signature in a file). So this seems to be a bug with how xxd works in OS X 10.8.2.

Is there an open-source alternative to xxd which works on Mac OS X and sends a byte-representation of standard input to standard output?

share|improve this question
    
I don't have a Mac so I can't say for sure but od and hexdump support the functionality you need. But you'll have to confirm for us if this works on a Mac. –  dinesh Jan 3 '13 at 7:52
    
What options do I use with hexdump to get byte output? I can get hex output, but I don't see what option to use to get byte output identical to what xxd outputs. –  Alex Reynolds Jan 3 '13 at 15:27
1  
The first command works for me on 10.8.2. (Even though it's the hash of $'foo\n'.) openssl, xxd, and base64 are all preinstalled versions. –  Lri Jan 3 '13 at 17:25
    
The first command works for me as well, but xxd -p | xxd -r does not, and should not be expected to (and is not at all the same as xxd -p -r). xxd -p does a plaintext hex dump (in this case, of something that is already a plaintext hex dump); xxd -r attempts to do a reverse (hex -> binary) conversion, but it expects a formatted (not plaintext) dump as input and will get confused when given a plaintext dump instead. –  Gordon Davisson Jan 3 '13 at 18:23
    
It works for me on Linux, but not for Mac OS X 10.8.2 on my MacBook Air. Neither the pre-installed version of xxd nor the one I compiled. xxd -p works, but xxd -p -r gives a blank string. Is there an alternative to xxd that works the same as xxd -p -r? –  Alex Reynolds Jan 3 '13 at 18:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.