Encoding to base64

248 views Asked by At

The base64 string ADEwNjcANDEzNDgxODdCNjcyNzIxMzU5NjU1M0VBM0JFOEE5QzM= when decoded is 106741348187B6727213596553EA3BE8A9C3. When I encode 106741348187B6727213596553EA3BE8A9C3 to base64 the result is MTA2NzQxMzQ4MTg3QjY3MjcyMTM1OTY1NTNFQTNCRThBOUMz.

I'm certain that the un-encoded string is the input for the first base64 string because the un-encoded string is made up of a user id and an authorization token joined. So if decoding from base64 gives me these two specific strings joined, but encoding results in something different from the string from which they were decoded, how exactly was the un-encoded string encoded to the base64 string to begin with?

1

There are 1 answers

3
user3553031 On BEST ANSWER

The problem is that the result of decoding your input isn't 106741348187B6727213596553EA3BE8A9C3; it's \01067\041348187B6727213596553EA3BE8A9C3. Note the two null bytes, which are presumably getting stripped before you re-encode it.

If you decode and re-encode without stripping those nulls, you get the input back:

$ echo "ADEwNjcANDEzNDgxODdCNjcyNzIxMzU5NjU1M0VBM0JFOEE5QzM=" | base64 -d | base64
ADEwNjcANDEzNDgxODdCNjcyNzIxMzU5NjU1M0VBM0JFOEE5QzM=

To better see what's going on, look at the actual bytes being output by your decoder:

$ echo "ADEwNjcANDEzNDgxODdCNjcyNzIxMzU5NjU1M0VBM0JFOEE5QzM=" | base64 -d | od -c
0000000  \0   1   0   6   7  \0   4   1   3   4   8   1   8   7   B   6
0000020   7   2   7   2   1   3   5   9   6   5   5   3   E   A   3   B
0000040   E   8   A   9   C   3
0000046