title: How can I save private key with passphase using phpseclib?
body: <p>I am trying to create self-signed certificates without using openssl or any command line application in PHP. Is it possible? I have found a library on the internet named phpseclib. But I am not sure if it is possible to produce certificates in .crt format. My objective is to sign pdfs with those self-signed certificates for which the certificates must be in .crt format. The private key must have a passphrase. how do I save the private key with a passphrase?? I am using the code below</p>
  <pre><code>// create private key / x.509 cert for stunnel / website
  $CAPrivKey = RSA::createKey();
  $CAPubKey = $CAPrivKey-&gt;getPublicKey();
  
  $CASubject = new X509;
  $CASubject-&gt;setDNProp('id-at-organizationName', 'phpseclib CA cert');
  $CASubject-&gt;setPublicKey($CAPubKey);
  
  $CAIssuer = new X509;
  $CAIssuer-&gt;setPrivateKey($CAPrivKey);
  $CAIssuer-&gt;setDN($CASubject-&gt;getDN());
  
  $x509 = new X509;
  // $x509-&gt;makeCA();
  $result = $x509-&gt;sign($CAIssuer, $CASubject);
  
  file_put_contents(&quot;2.key&quot;, $CAPrivKey);
  
  $cert =  $x509-&gt;saveX509($result);
  file_put_contents(&quot;2.crt&quot;, $cert);
  </code></pre>