> a final newline to encoded data (which seems to be RFC compliant, as > lines are supposed to be folded as "at most" 76 characters, and this is > also how the Perl base64 behaves).
Yup, Base64 is a mail transport encoding defined in http://www.ietf.org/rfc/rfc1521.txt for transport of MIME data over SMTP. SMTP mail transport specifies compulsory wrapping at char 300, and advises wrapping at or before 76, for reasons which are archaic but nevertheless form part of the standard. Therefore any Base64 implementation MUST by design be capable of wrapping and un-wrapping at or before char 76. The rfc makes no mention of any trailing CRLF, because the boundary of the Base64 encoded data is defined by the length of the encoded string, and padding with "=" is used to lengthen any sortfall to the next boundary, therefore the trailing CRLF will never be considered part of the encoded data. d.