Page 1 of 1

PHP Base64 didn't follow MIME

Posted: Tue Jun 02, 2009 11:13 pm
by zoftdev
from wiki :http://en.wikipedia.org/wiki/Base64
IME does not specify a fixed length for base64-encoded lines, but it does specify a maximum line length of 76 characters. Additionally it specifies that any extra-alphabetic characters must be ignored by a compliant decoder, although most implementations use a CR/LF newline pair to delimit encoded lines.

http://www.developer.com/java/other/article.php/3386271
According to RFC 1521, the output stream of encoded characters must be represented in lines of no more than 76 characters each.
But php's base64 didn't put a newline

Example of problem:
Jj4rK1k0TVLDnh1xnwOzum5JekxNY9L0y3JLahskxkmiQWgxc7pMeZARb8SpAEGuRMenb4rBd1Y2lOuTkvBkI8twHcC2FPFNhYJfWdk6PGPOFUr7ljH3gOSelX72neVPQSZyUoNoeQNn3x3ypWQ65dJmBwFAQBtQgam4BJtfvwE=

Java base64:
Jj4rK1k0TVLDnh1xnwOzum5JekxNY9L0y3JLahskxkmiQWgxc7pMeZARb8SpAEGuRMenb4rBd1Y2
lOuTkvBkI8twHcC2FPFNhYJfWdk6PGPOFUr7ljH3gOSelX72neVPQSZyUoNoeQNn3x3ypWQ65dJm
BwFAQBtQgam4BJtfvwE=

Please suggestion this is optional or required

Re: PHP Base64 didn't follow MIME

Posted: Wed Jun 03, 2009 12:40 am
by requinix
That RFC is talking about what happens inside a mail body.

base64_encode has nothing to do with it. If you need to stick the result into a mail body then use chunk_split.

Re: PHP Base64 didn't follow MIME

Posted: Wed Jun 03, 2009 1:11 am
by zoftdev
I don't use in mail body but use to send data to partner. Their encryption method stick with message size.
tasairis wrote:That RFC is talking about what happens inside a mail body.

base64_encode has nothing to do with it. If you need to stick the result into a mail body then use chunk_split.

Re: PHP Base64 didn't follow MIME

Posted: Wed Jun 03, 2009 4:57 am
by Mark Baker
Use the iconv_mime_encode() function instead. This does allow you to specify the line length size, defaulting to 76 bytes

Re: PHP Base64 didn't follow MIME

Posted: Tue Jun 09, 2009 3:26 am
by zoftdev
Thanks!