coder
coder

Reputation: 4466

Base64 encoding, DONT_BREAK_LINES option

I am using Base64.encodeBytes to encode by signed data, but it adds new line character to the generated string (for every 76 characters). I found out that there is an option to pass DONT_BREAK_LINES to avoid new line chars.

But the description of this fields says /** Don't break lines when encoding (violates strict Base64 specification) */

Can someone please explain, why using this option violates Base64 spec ?

Upvotes: 0

Views: 2279

Answers (1)

Murph
Murph

Reputation: 1509

The term Base64 originated from MIME content transfer encoding.

The latest version of the RFC that defines this is here, RFC 5322.

It says:

2.1.1.  Line Length Limits

   There are two limits that this specification places on the number of
   characters in a line.  Each line of characters MUST be no more than
   998 characters, and SHOULD be no more than 78 characters, excluding
   the CRLF.

And since CR and LF are each one character, that leaves 76 characters for the lines.

TBH it only violates the suggestion of the text and really nobody cares. If you had a line longer than 996 characters, then you would be in violation .. and probably nobody would care.

Upvotes: 1

Related Questions