title: Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate
body: <p>After generating a private and csr keys, I am getting this warring:</p>
  
  <pre><code>Warning: openssl_x509_read(): supplied parameter cannot be coerced into an X509 certificate! in .../libs/ACMECert/ACMECert.php on line 313 
  </code></pre>
  
  <p>Private key generated:</p>
  
  <pre><code>-----BEGIN PRIVATE KEY-----
  MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDUcL30x/uEDLoV
  l3Sw+fadN5ElHEohR33z/5oNAun+tpGATRplNiiO7mfWHXLY6g39anhPaHFBGLd3
  KSSFhZobM7D7B+F6A1Q2IAJLQ//6xopUagIUl6IuMn6xgXCNoV75D97vAAYjM8Q8
  iwOMmCo3ayhtOjRlmf5XiIiSBq5jbQgCVUn5wcGp2XGseofYYiK4ZA+54b9k5UJJ
  3pHh5rERJ93G3JgSUQaXPLtgOpBB2XSS8trfedQWbx79Fb2rSPYdMeZCwV78pkl6
  gSARDfeGvatCsVAZcerRLVbCZlfK1RSQ7hQA7HkZJIbU4Bk8hMF9yeJV33q6oYBn
  P6xZRm33AgMBAAECggEAXgLObSaarWMcbjWqFC9p7UUL3Epam8ORf4rbV2q0tl2A
  ojB8v9FpvWbPWLeLfWaGbmDRgQKNK+uONRNl8Bihi+wiI9Tm+SHEAHfFzBz5iLaX
  vKd06Dv6L0t1OYQ4lNSWvM1DMKzoCmf8LXavSWaFOCUZrMyXJ2cwYPgwx75hKenl
  uItuoSdTOLzNjGUWuS0dkVoBR4rXMpCiM7madGeSOfQR/mS/8j/9VLZxDwnVyWza
  Sm3fua99pDYL8B+i82OGTHN1eHBu0SuHgmodRH6OxXiL4flqsLjaOJMluKvH6PNs
  sF9rJdUoGYt1KwqYJHuCunGp4jOXv5UB+T1417p9EQKBgQDr+EAMfJu5UBOghS9V
  gG9BdjfPy0pQ4b30qF/C7obX5GQSPN3kRo0GWw5xoGAzR6YMinKn11T5XJQ7SEp7
  pMF65D4iWapvYQ3Do0u/U+HgpckFqid8zJ4rakYFpWpZJUt387zZuEcT+IcDHv0r
  As2AsKcKoazgwoU2/zDEk9WJpQKBgQDmeS/REhzwAVyLQDuvxcaCSzKiiIhv2/jZ
  Usu1Gu/LCcorKpqi/4uVI9aIRER0yApPe57qddW8PYDaXaPhTt71nhgG9gxnMv44
  o/HatGrbDJotEVU6d/W0ntY+LBCymsZGIQx581bn+OpbGhwsATnqwZ9M0kjdD74S
  Tmlzpo1uawKBgEYnPAN6WGGzqOIkNnpZALqZhuZELgf11R+Tn0S43WX6BLZXWjCv
  uOWW1Kh7YZ5dQsSftI6puh2YpIkraNlxlgQPL1nPBpiuZgUv2yk6qwC6yRTiDXNQ
  8gU+RysOjpuKNvGmiRLBcoBBdwI6iFHtN2N3IXJLtrXrnudG3xzSRr3xAoGBAJBg
  tHq1bRlQ0QeOypU3QT7YGrVE8KuaUo7Z1jDy2esIi/R0sQCRM4DPPZKJqZS6x/K4
  z3mzLZzJrpGc/Y+kV/nn+sdJlcWEZUtYMKdARHxKrb6zz/9brLlkk3PJKQCqArFl
  /KncrcGN5koB1koezohomQGH7gtF1F0lb9v6JzlXAoGAFFyply/b3rWxTXkx9o/L
  tGQboJoDRYt4RyS8DLJjnVZ0y1ELXBqazm9f3xPJi3FTBd2l1VKkH18tAdcfZ0uE
  I0rh0ziWeOJCmhdqkVngLzB376HjzK6K57AbhGFl0WayoefM6TOAkcMds3h/vLpv
  Fv4TflcdFP2UGeP4B13n5Cs=
  -----END PRIVATE KEY-----
  </code></pre>
  
  <p>CSR key generated:</p>
  
  <pre><code>-----BEGIN CERTIFICATE REQUEST-----
  MIICojCCAYoCAQAwJTEjMCEGA1UEAwwaYXBwbGUuaGlnaHNjaG9vbGhlbHBlci5v
  cmcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDUcL30x/uEDLoVl3Sw
  +fadN5ElHEohR33z/5oNAun+tpGATRplNiiO7mfWHXLY6g39anhPaHFBGLd3KSSF
  hZobM7D7B+F6A1Q2IAJLQ//6xopUagIUl6IuMn6xgXCNoV75D97vAAYjM8Q8iwOM
  mCo3ayhtOjRlmf5XiIiSBq5jbQgCVUn5wcGp2XGseofYYiK4ZA+54b9k5UJJ3pHh
  5rERJ93G3JgSUQaXPLtgOpBB2XSS8trfedQWbx79Fb2rSPYdMeZCwV78pkl6gSAR
  DfeGvatCsVAZcerRLVbCZlfK1RSQ7hQA7HkZJIbU4Bk8hMF9yeJV33q6oYBnP6xZ
  Rm33AgMBAAGgODA2BgkqhkiG9w0BCQ4xKTAnMCUGA1UdEQQeMByCGmFwcGxlLmhp
  Z2hzY2hvb2xoZWxwZXIub3JnMA0GCSqGSIb3DQEBDQUAA4IBAQAdfcUvD5csPYFF
  Asgc8wlPFWcKOWEfTBKCTLLN9f5p0rOJB7YYxrG0nvlbSrDNgB+G60hFcdXfRgeY
  1P0JAplLZTYv4JyfFTJyNtwZidjwq0IPe171Mqv7GzXiaGj1qgZTUBeLqwybX+K9
  v81zGKrRrx5B30YViNBY/b3/ErFaDnFzX5NOHKBRHrhXkUFQTDRxpXBGJrIb61l4
  Ix4cnHbGwHAMVO+8A0cEWHqG4W3lYdRwMb+/jyf8RJ3/qTq4EAtdY7xMMs2kJsnM
  nFwq12z1CwOStETUSErDhmRzzYGuG29bg4sn2GQHtTP8B2e8vpFJJVlDYIH/SPi8
  nuA0v3cW
  -----END CERTIFICATE REQUEST-----
  </code></pre>
  
  <p>Library used:</p>
  
  <pre><code>https://github.com/skoerfgen/ACMECert
  </code></pre>
  
  <p>Code used to generate keys:</p>
  
  <pre><code>&lt;?php
  
  ini_set('display_errors', 1);
  ini_set('display_startup_errors', 1);
  error_reporting(E_ALL);
  
  require_once __DIR__ . '/config.php';
  require_once __DIR__ . '/libs/ACMECert/ACMECert.php';
  
  
  $domain_name = 'apple.highschoolhelper.org';
  
  $ac = new ACMECert(false);
  if (!file_exists($letsencrypt_certificate_dir . $domain_name)) {
      mkdir($letsencrypt_certificate_dir . $domain_name);
  }
  
  
  // Avoid any UTF-8 header
  // https://github.com/skoerfgen/ACMECert/issues/8#issuecomment-557766088
  $letsencrypt_account_key = $letsencrypt_certificate_dir . '/letsencrypt-account_key.pem';
  if(file_exists($letsencrypt_account_key)) {
      $letsencrypt_account_key = preg_replace('/[\x00-\x09\x0b-\x1f\x7f-\xff]/', '', file_get_contents($letsencrypt_account_key));
      $ac-&gt;loadAccountKey($letsencrypt_account_key);
  }
  else {
      $letsencrypt_key = $ac-&gt;generateRSAKey(2048);
      file_put_contents($letsencrypt_certificate_dir . '/letsencrypt-account_key.pem', $letsencrypt_key);
      chmod($letsencrypt_certificate_dir . '/letsencrypt-account_key.pem', 777);
      $ret = $ac-&gt;register(true, $letsencrypt_account);
  }
  
  $ret = $ac-&gt;getAccount();
  
  echo "&lt;pre&gt;";
  print_r($ret);
  echo "&lt;/pre&gt;";
  
  
  $domain_config=[
    'apple.highschoolhelper.org' =&gt; ['challenge' =&gt; 'http-01', 'docroot' =&gt; '/var/www/html/apple.highschoolhelper.org/public_html'],
  ];
  
  $prepare_cert_handler = function($opts){
    $fn = $opts['config']['docroot'] . $opts['key'];
    @mkdir(dirname($fn),0777,true);
    file_put_contents($fn, $opts['value']);
    /*return function($opts){
      unlink($opts['config']['docroot'] . $opts['key']);
    };*/
  };
  
  
  
  $domain_private_key = $letsencrypt_certificate_dir . $domain_name . '/' . $domain_name . '_key.pem';
  if(file_exists($domain_private_key)) {
      $domain_private_key = preg_replace('/[\x00-\x09\x0b-\x1f\x7f-\xff]/', '', file_get_contents($domain_private_key));
  }
  else {
      $domain_private_key = $ac-&gt;generateRSAKey(2048);
      file_put_contents($letsencrypt_certificate_dir . $domain_name . '/' . $domain_name . '_key.pem', $domain_private_key);
      chmod($letsencrypt_certificate_dir . $domain_name . '/' . $domain_name . '_key.pem', 777);
      chown($letsencrypt_certificate_dir . $domain_name . '/' . $domain_name . '_key.pem', 'apache');
  }
  
  //$fullchain = $ac-&gt;getCertificateChain($domain_private_key, $domain_config, $prepare_cert_handler);
  //file_put_contents($letsencrypt_certificate_dir . $domain_name . '/' . $domain_name . '_fullchain.pem',$fullchain);
  
  
  
  $domain_csr = $ac-&gt;generateCSR($domain_private_key, ['apple.highschoolhelper.org']);
  
  file_put_contents($letsencrypt_certificate_dir . $domain_name . 'CSR_key.pem', $domain_csr);
  print_r($domain_private_key);
  //$ret = $ac-&gt;parseCertificate(file_get_contents('/etc/letsencrypt/live/self-signed-cert.pem'));
  $ret = $ac-&gt;parseCertificate($domain_csr);
  
  
  echo "&lt;pre&gt;";
  print_r($domain_csr);
  echo "&lt;/pre&gt;";
  </code></pre>