Why base64 decodes strings are different in Python2.7 and in Linux

I have following commands in linux as, base64 encoded string 'rITqHhVbOjGIWelaJbg==' in file test64.dat. used commands -

# base64 -d -i test64.dat >> test.dat
# echo "IV=" `hexdump test.dat | head -1 | cut -f 2- -d ' ' | sed s/' '//g ` >> abc.txt
# cat abc.txt
IV= 84ac1eea7515e86c21c6a5676f6b6ec9

I want to use python base64 module for decoding same string as in test64.dat, i tried below code

hexdump.dump(base64.b64decode('rITqHhVbOjGIWelaJbg==')) 

It gives output as.

'AC 84 EA 1E 15 5B 3A 31 88 59 E9 5A 25 B8'

Can anyone please tell me why base64 decoded output is different, am i doing something wrong?

Jon Skeet
people
quotationmark

There are two issues here:

1) Your input is invalid. It has too many = at the end, so the Linux output includes "base64: invalid input" which you're merrily decoding as hex afterwards.

2) hexdump isn't giving you the format you really want; it's treating it as a sequence of pairs of bytes, and reversing each pair. For example, input of "ABCD" ends up with default output of "4241 4443" - note the ordering of 42 before 41, and 44 before 43.

Once you've fixed the input, you can pass an output format to hexdump to give you the format you want

echo rITqHhVbOjGIWelaJbg= | base64 -d | hexdump -e '16/1 "%02X " "\n"'

Output:

AC 84 EA 1E 15 5B 3A 31 88 59 E9 5A 25 B8

people

See more on this question at Stackoverflow