title: Using Node's crypto Library to Create a Self-signed Certificate?
body: <p>Is it possible in pure JavaScript (no openssl binary) to use Node's crypto library to generate a self-signed certificate? Here is my script that uses openssl to generate a certificate:</p>
  
  <pre><code>#!/bin/bash
  FQDN="*"
  
  # Create a private key
  openssl genrsa \
      -out server-key.pem \
      2048
  
  # Create a certificate signing request
  openssl req \
      -new \
      -key server-key.pem \
      -out certificate-signing-request.csr \
      -subj "/C=US/ST=StateL=City/O=Full Name/CN=${FQDN}"
  
  # Sign the certificate signing request to create the server certificate
  openssl x509 \
      -req -in certificate-signing-request.csr \
      -signkey server-key.pem \
      -out server-certificate.pem \
      -days 36159
  </code></pre>
  
  <p>I'm curious if this could all be done using JavaScript and the classes and methods available here:</p>
  
  <p><a href="https://nodejs.org/api/crypto.html" rel="noreferrer">https://nodejs.org/api/crypto.html</a></p>
  
  <p>If so, what would the code look like to create files above?</p>