# Can I remove newlines in a public key?

Can I remove new lines from the RSA public key file to get a one line string? So the question is if the key looks like this

AAA
BBB
CCC


or

AAA\n\rBBB\n\rCCC\n\r


is this the same as

AAABBBCCC


I'm assuming you mean a base 64 encoded key file, since removing the newlines from a binary file would obviously break things.

The RSA standards (e.g. RFC 2459) only define a binary representation for keys. In practice, like OpenPGP keys (RFC 4880), they are often encoded in base 64 using the otherwise obsolete PEM standards (RFC 1421).

The PEM printable encoding section says:

To represent the encapsulated text of a PEM message, the encoding function's output is delimited into text lines (using local conventions), with each line except the last containing exactly 64 printable characters and the final line containing 64 or fewer printable characters.

The OpenPGP radix 64 section says:

The encoded output stream must be represented in lines of no more than 76 characters each.

For SSH, on the other hand, RFC 4716 Section 3:

A key file is a text file, containing a sequence of lines. Each line in the file MUST NOT be longer than 72 8-bit bytes excluding line termination characters.

Do implementations in practice accept longer lines? I would expect many to do so. However, while no information is lost, it's technically nonconforming to use such encodings.

• 4880 notes MIME 2405 which also says 76, not earlier 1421 which says 64; PGP & PEM have dashed BEGIN and END lines while MIME has other boundaries. More relevant to SSH is 4716, which cites all three but specifies different BEGIN/END lines and internal headers and max width 72. Unrelated but analogous, OpenSSL has many crypto primitives same as SSH and uses nominal PEM for many things; it writes 64 chars (per 1421), reads 76 chars (per 2405) in most cases and silently drops anything longer, although there has recently been discussion on the dev list about fixing this. – dave_thompson_085 Sep 10 '14 at 6:53
• @dave_thompson_085, I missed the ssh tag. If the question is specifically about SSH, 4716 is indeed most relevant. – otus Sep 10 '14 at 8:49