title: OpenSSL in the browser - need to get private key from .pem and then sign
body: <p>I've got a php file which looks like this:</p>
  
  <pre><code>$key = '../certs/private/private-key-hoobu.pem';
  $pass = '';
  
  $req = $_GET['request'];
  $privateKey = openssl_get_privatekey(file_get_contents($key), $pass);
  
  $signature = null;
  openssl_sign($req, $signature, $privateKey);
  
  if($signature) {
      header("Content-type: text/plain");
      echo base64_encode($signature);
      exit(0);
  }
  </code></pre>
  
  <p>I have a Windows store app I've with javascript, and for a feature I'm working on <strong>I need to be able to recreate this code in javascript</strong></p>
  
  <p>Now I've looked into browser-based openSSL solutions and found <a href="https://www.npmjs.com/package/node-forge" rel="nofollow noreferrer">node-forge</a> but it looks like it requires being used in like a webpack/browserify type environment, but I just need it as like a global library, don't know how to get that.</p>
  
  <p>Secondly, php code above says <code>openssl_get_privatekey(file_get_contents($key), $pass);</code> but the node-forge code that I think matches, <code>pki.privateKeyFromPem(pem);</code>, doesn't even take a <code>$pass</code> variable as an argument. I'm kind of confused about that.</p>