big-list-of-naughty-strings icon indicating copy to clipboard operation
big-list-of-naughty-strings copied to clipboard

Newlines characters in base64

Open mcarton opened this issue 9 years ago • 3 comments

All base64 strings¹ end with a newline character, eg.:

>>> base64.b64decode("dW5kZWZpbmVkCg==")
b'undefined\n'
>>> base64.b64decode("dW5kZWYK")
b'undef\n'
>>> base64.b64decode("Q09NMQo=")
b'COM1\n'

Is this on purpose? That newline character seems pretty useless. If not, that line should probably read echo -n.


1: all but the empty string itself, which makes it even more annoying because it makes two cases to handle.

mcarton avatar Dec 03 '15 22:12 mcarton

The newline character is added by the python decode method. This is not a problem with the base64 itself

base64.b64decode('Q09NMQo=').rstrip('\n')

romuald avatar Feb 10 '16 13:02 romuald

@romuald: No, it isn’t.

$ printf 'COM1\n' | base64
Q09NMQo=
$ printf 'COM1' | base64
Q09NMQ==

charmander avatar Feb 10 '16 21:02 charmander

Oops, sorry. You're right, confounded the decode and encode behaviors …

romuald avatar Feb 10 '16 22:02 romuald