Ruby Padding Issues with Base64 Decoding
blog.vidyard.comGreat article!
Why is it that the encoded string needs to be divisible by four before you can decode it?
If I remember the decoding process right, it's basically just taking 4 characters at a time, multiplying by (6/8) (which is 3/4) to get 3 characters.
This doesn't make it impossible to decode less than 4 characters, but you can't tell if the shortage is due to an error (early truncation) or just the padding being stripped (the article doesn't make it clear, but = is the traditional padding character used to make the encoded text have the proper length). Obviously both encoder/decoder will need to agree on the padding style to be used if it is important that encoded text be canonical.