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




is this the same as


1 Answer 1


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.

  • 5
    $\begingroup$ 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. $\endgroup$ Sep 10, 2014 at 6:53
  • $\begingroup$ @dave_thompson_085, I missed the ssh tag. If the question is specifically about SSH, 4716 is indeed most relevant. $\endgroup$
    – otus
    Sep 10, 2014 at 8:49
  • 2
    $\begingroup$ Not sure why this Q showed active in 2019 but since it did: 'PEM' format was respecified -- still with lines broken at 64 -- by rfc7468 in 2015. OpenSSL 1.1.0 in 2016-08 up does read lines longer than 76, but still not infinite. And not SSH format(s), of course. $\endgroup$ Aug 24, 2019 at 5:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.