title: Why is phpseclib producing incompatible certs?
body: <p>Why is it that when I try to use a certificate/key pair generated from phpseclib, the OpenSSL server code errors out? Certs/Keys generated from OpenSSL work fine. How do I fix this?</p>
  
  <p>Certificate/Key Generation taken straight from <a href="http://phpseclib.sourceforge.net/x509/examples.html#selfsigned" rel="nofollow">phpseclib documentation</a>:</p>
  
  <pre><code>&lt;?php
  include('File/X509.php');
  include('Crypt/RSA.php');
  
  // create private key / x.509 cert for stunnel / website
  $privKey = new Crypt_RSA();
  extract($privKey->createKey());
  $privKey->loadKey($privatekey);
  
  $pubKey = new Crypt_RSA();
  $pubKey->loadKey($publickey);
  $pubKey->setPublicKey();
  
  $subject = new File_X509();
  $subject->setDNProp('id-at-organizationName', 'phpseclib demo cert');
  //$subject->removeDNProp('id-at-organizationName');
  $subject->setPublicKey($pubKey);
  
  $issuer = new File_X509();
  $issuer->setPrivateKey($privKey);
  $issuer->setDN($subject->getDN());
  
  $x509 = new File_X509();
  //$x509->setStartDate('-1 month'); // default: now
  //$x509->setEndDate('+1 year'); // default: +1 year
  
  $result = $x509->sign($issuer, $subject);
  echo "the stunnel.pem contents are as follows:\r\n\r\n";
  echo $privKey->getPrivateKey();
  echo "\r\n";
  echo $x509->saveX509($result);
  echo "\r\n";
  ?>
  </code></pre>