Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Ruby Padding Issues with Base64 Decoding (vidyard.com)
9 points by michaelrlitt on Oct 17, 2012 | hide | past | favorite | 2 comments


Great 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: