Why some base64 strings cannot be symetrically encoded?

Viewed 17

I have thought that base64 can be symetrically encoded/decoded, but I found that some base64 strings are not encoded back to same string after decoding.

Examples in bash:

printf "fV==" | base64 -d | base64
fQ==
printf "fS==" | base64 -d | base64
fQ==
printf "Ck==" | base64 -d | base64
Cg==
printf "Pm==" | base64 -d | base64
Pg==
printf "cK==" | base64 -d | base64
cA==

Example in python:

from binascii import a2b_base64, b2a_base64

b2a_base64(a2b_base64(b'am==')) == b'ag==\n'

I have tried other online encoder/decoders and it behaves the same.

Why is it so?

Is there some normal base64 form?

How can I encode back to original form after decoding?

0 Answers
Related