title: How to fix openssl_private_decrypt() error in PHP?
body: <p>I need finish this part of school project.</p>
  
  <p><strong>Create openssl public and private key</strong></p>
  
  <pre><code>function openssl($text){
      # privaten Schlüssel erzeugen
      $res=openssl_pkey_new();
      # privaten Schlüssel zu String
      openssl_pkey_export($res, $privatekey);
      # öffentlichen Schlüssel
      $publickey=openssl_pkey_get_details($res);
      $publickey=$publickey["key"];
      openssl_public_encrypt($text, $crypttext, $publickey);
      $filenameCrypttext = "crypttext.txt";
      $filenamePrivatekeyText = "privatekey.txt";
      $files = [$filenameCrypttext, $filenamePrivatekeyText];
      createFile($crypttext, $filenameCrypttext);
      createFile($privatekey,$filenamePrivatekeyText);
      downloadZip($files);
  }
  function createFile($crypttext, $filename){
      file_put_contents($filename, $crypttext.PHP_EOL , FILE_APPEND | LOCK_EX);
  }
  
  function downloadZip($files){
      $zipname = "packet.zip";
      $zip = new ZipArchive;
      $zip-&gt;open($zipname, ZipArchive::CREATE);
      foreach ($files as $file){
          $zip-&gt;addFile($file);
      }
      $zip-&gt;close();
      foreach ($files as $file) {
          unlink($file);
      }
  
      header("Location: download.php?filename=$zipname");
  }
  </code></pre>
  
  <p>I download my 2 files <em>crypttext.txt</em> and <em>privatekey.txt</em> as zip. Later I want to upload them.</p>
  
  <p><a href="https://pastebin.com/LAvGLdFf" rel="nofollow noreferrer"><strong>Encrypted</strong></a></p>
  
  <p><a href="https://pastebin.com/0awFyxQx" rel="nofollow noreferrer"><strong>Privatekey</strong></a></p>
  
  <p><strong>And the following code is my decryption function</strong></p>
  
  <pre><code>&lt;div class="container"&gt;
  &lt;br&gt;
  &lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="post"&gt;
      &lt;label&gt;Encrypted Text&lt;/label&gt;
      &lt;textarea name="encrypted_text"  placeholder="Text einfügen" class="form-control" rows="3"&gt;&lt;/textarea&gt;
      &lt;label&gt;Private Key &lt;/label&gt;
      &lt;textarea name="private_key"  placeholder="Text einfügen" class="form-control" rows="3"&gt;&lt;/textarea&gt;
      &lt;br&gt;
      &lt;button type="submit" class="btn btn-primary"&gt;Hochladen&lt;/button&gt;
  &lt;/form&gt;
  &lt;?php
  if(isset($_POST['encrypted_text'], $_POST['private_key'])){
      echo 'isset';
      $encrypted = $_POST['encrypted_text'];
      $privatekey = $_POST['private_key'];
      $res = openssl_get_privatekey($privatekey);
      openssl_private_decrypt($encrypted, $decrypted, $res);
      echo '&lt;br&gt;';
      echo $decrypted;
      echo '&lt;br&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p></p>
  
  <p>I dont get a result.
  Where is my misstake?</p>