What is the maximum length of private and public RSA keys?
<p>I am generating private and public keys using OpenSSL in PHP, which I intend to store in a database (although you probably don't need to know PHP to answer this question).</p>

<p>They look like this:</p>

<pre><code>-----BEGIN ENCRYPTED PRIVATE KEY-----
MIIFDjBABgkqhkiG9w0BBQ0wMzAbBgkqhkiG9w0BBQwwDgQIi4rlLSKA9/8CAggA
...
-----END ENCRYPTED PRIVATE KEY-----
</code></pre>

<p>and</p>

<pre><code>-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA8YvAFZHSGNITeDNdXFbc
...
-----END PUBLIC KEY-----
</code></pre>

<p>(and yes those are just examples)</p>

<p>They have been created like so:</p>

<pre><code>$resource = openssl_pkey_new([
        'private_key_bits' =&gt; '2048',
        "private_key_type" =&gt; OPENSSL_KEYTYPE_RSA,
]);
openssl_pkey_export($resource, $privateKey, $passPhrase) === false
$opensslDetails = openssl_pkey_get_details($resource);
$publicKey = $opensslDetails['key'];
</code></pre>

<p>I want to know what the maximum length is for these private and public keys.</p>

<p>From my experimentation, I have found that:</p>

<ul>
<li>1704 characters for private keys</li>
<li>1834 characters for private keys with passphrase</li>
<li>451 characters for public keys</li>
</ul>

<p>However I haven't found any formal documentation on this to prove that this is the case, so I can't be sure.</p>