Trailing = in base64_encode

Is it safe to remove trailing == of base64_encode or it will fail decoding?

There was a recent post here where someone needed help with failed decoding due to the == having been mishandled - base 64 encoded strings need to be a multiple of 3 in length in order to be base 64 encoded and the = are there if needed to fill up the last triplet.

Some processes may still work if you remove them but as decoding base 64 is supposed to work three characters at a time, it will likely result in the loss of at least one character off the end of the decoded string.

1 Like

Some time ago I tested it and PHP base64_decode had no problem with the removed trailing =. I would suggest that if you intend to share the encoded data with other systems then leave the =, for PHP usage only you should be fine with truncating them.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.