PHP Base64 didn't follow MIME

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zoftdev
Forum Newbie
Posts: 6
Joined: Tue Jun 02, 2009 11:01 pm

PHP Base64 didn't follow MIME

Post 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
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: PHP Base64 didn't follow MIME

Post 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.
zoftdev
Forum Newbie
Posts: 6
Joined: Tue Jun 02, 2009 11:01 pm

Re: PHP Base64 didn't follow MIME

Post 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.
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: PHP Base64 didn't follow MIME

Post by Mark Baker »

Use the iconv_mime_encode() function instead. This does allow you to specify the line length size, defaulting to 76 bytes
zoftdev
Forum Newbie
Posts: 6
Joined: Tue Jun 02, 2009 11:01 pm

Re: PHP Base64 didn't follow MIME

Post by zoftdev »

Thanks!
Post Reply