Take the 2-minute tour ×
Cryptography Stack Exchange is a question and answer site for software developers, mathematicians and others interested in cryptography. It's 100% free, no registration required.

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
share|improve this question

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
2  
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 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 at 8:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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