title: How to generate a string containing private and public key in PhP?
body: <p>I saw this code:</p>
  
  <pre><code>&lt;?php
  class MyEncryption
  {
  
      public $pubkey = '...public key here...';
      public $privkey = '...private key here...';
  
      public function encrypt($data)
      {
          if (openssl_public_encrypt($data, $encrypted, $this-&gt;pubkey))
              $data = base64_encode($encrypted);
          else
              throw new Exception('Unable to encrypt data. Perhaps it is bigger than the key size?');
  
          return $data;
      }
  
      public function decrypt($data)
      {
          if (openssl_private_decrypt(base64_decode($data), $decrypted, $this-&gt;privkey))
              $data = $decrypted;
          else
              $data = '';
  
          return $data;
      }
  }
  
  
  ?&gt;
  </code></pre>
  
  <p>What are samples of public_key? What kind of public key should be put on $pubkey? Should it be base_64encoded or not? How do I generate one?</p>
  
  <p>I added:</p>
  
  <pre><code>$privKey = openssl_pkey_new();
  </code></pre>
  
  <p>And all I got is $privKey==false</p>