title: Encrypt string in PHP using SSH2 public key
body: <p>I have a public key in such a format (PuTTY format?):</p>
  <pre><code>---- BEGIN SSH2 PUBLIC KEY ----
  Comment: &quot;rsa-key-foobar&quot;
  AAA...
  ...kA+Tw==
  ---- END SSH2 PUBLIC KEY ----
  </code></pre>
  <p>I just want to encrypt a strings containing a few kilobytes of text.</p>
  <p>Now, <code>openssl_public_encrypt</code> seems to be wrong here:</p>
  <pre><code>openssl_public_encrypt($plain, $encrypted, $pubKey);
  =&gt; openssl_public_encrypt(): key parameter is not a valid public key
  </code></pre>
  <p>Even with <a href="https://phpseclib.com/" rel="nofollow noreferrer">phpseclib3</a> I can't get that running:</p>
  <pre><code>$rsa = RSA::load($pubKey);
  echo base64_encode($rsa-&gt;encrypt($plain));
  
  =&gt; Fatal error: Uncaught LengthException: Message too long in ...\phpseclib3\Crypt\RSA\PublicKey.php:389
  </code></pre>