Java – Unix base64 encoding mismatch

Unix base64 encoding mismatch… here is a solution to the problem.

Unix base64 encoding mismatch

I found some differences in base64 encoding in many utilities of unix utilities
For example:
In Java and Python, if I code b I get Yg== but in UNIX I get Ygo=
I need to use B64 from Unix in Java and Python. How do I keep them consistent?

Solution

Line breaks are prohibited.

echo -n "b" | ...

Or add it.

>>> 'b\n'.encode('base64')
'Ygo=\n'

Related Problems and Solutions