in reply to Remove base64 encoded trailing character

The = characters at the end are padding, because Base64 can only encode strings that have a length that is a multiple of 3 characters.

Replies are listed 'Best First'.
Re^2: Remove base64 encoded trailing character
by hankcoder (Scribe) on Mar 26, 2016 at 18:09 UTC

    Corion, thank you for pointing it out. I understand now.

    so the following:

    123 -> MTIz 1234 -> MTIzNA== 12345 -> MTIzNDU= 123456 -> MTIzNDU2

    Just to confirm, when Decode back, it doesn't matter the encoded strings has "=" or not right? In that case I can safely remove all encoded padding = yes?

      Read Base64#Padding

      In theory, the padding character is not needed for decoding, since the number of missing bytes can be calculated from the number of Base64 digits. In some implementations, the padding character is mandatory, while for others it is not used. One case in which padding characters are required is concatenating multiple Base64 encoded files.

      Oh and:

      If you want to encode a large file, you should encode it in chunks that are a multiple of 57 bytes. This ensures that the base64 lines line up and that you do not end up with padding in the middle.

      Read the source for more: Base64.pm

        Thanks FreeBeerReekingMonk, that is a very useful explanation to me.