Search code examples
bashhexxxd

xxd converts hex file to 32 bytes binary on Mac, 30 bytes on busy box?


I am using xxd to convert a file containing the following hex private key:

608e9b6f67c65e47531e08e8e501386dfae63a540fa3c48802c8aad854510b4e

simply by

xxd -r -p hex > bin

this command generates a binary with 32 bytes on Mac OS Big Sur xxd V1.10 27oct98 by Juergen Weigert and generates 30 bytes on busy box docker image BusyBox v1.33.1 (2021-06-07 17:33:50 UTC) I have no idea why ?

It should generate a 32 bytes binary on busy box.

Update #1 hex (hexdump of the binaries)

binary in busy box

00000000  60 8e 9b 6f 67 c6 5e 47  53 1e 08 e8 e5 01 38 6d  |`..og.^GS.....8m|
00000010  fa e6 3a 54 0f a3 c4 88  02 c8 aa d8 54 51        |..:T........TQ|
0000001e

binary in Mac OS Big Sur

00000000  60 8e 9b 6f 67 c6 5e 47  53 1e 08 e8 e5 01 38 6d  |`..og.^GS.....8m|
00000010  fa e6 3a 54 0f a3 c4 88  02 c8 aa d8 54 51 0b 4e  |..:T........TQ.N|
00000020

Solution

  • I figured it out. In xxd busybox implementation, argument -c defaults to a 30, changing it to 32, gives the same result as Mac OS Big Sur:

    xxd -r -p -c 32 hex > bin