title: P12 certificate "Not enough data" error
body: <p>I was trying to connect to an endpoint securely using a <code>.p12</code> file but I keep getting the following error.</p>
  
  <pre><code>_tls_common.js:136
    c.context.loadPKCS12(pfx);
              ^
  
  Error: not enough data
  at Error (native)
  at Object.createSecureContext (_tls_common.js:136:17)
  at Object.TLSSocket._init.ssl.onclienthello.ssl.oncertcb.exports.connect (_tls_wrap.js:1003:48)
  at Agent.createConnection (https.js:80:22)
  at Agent.createSocket (_http_agent.js:179:26)
  at Agent.addRequest (_http_agent.js:141:10)
  at new ClientRequest (_http_client.js:147:16)
  at Object.exports.request (http.js:31:10)
  at Object.exports.request (https.js:197:15)
  at Request.start (D:\path_to_project\node_modules\request\request.js:747:30)
  </code></pre>
  
  <p>The code that generates the error is this:</p>
  
  <pre><code>        request({
              method: 'POST',
              url: config.secureEndpoint.hostname + config.secureEndpoint.path,
              body: XMLAPIResponse.body,
              rejectUnauthorized: false,
              strictSSL: false, 
              agentOptions: {
                  //pfx: pfx,
                  pfx: 'string_path_to_the_p12_key_file.p12',
                  passphrase: 'redacted_password'
              }
          }, function (error, response, body) {
              console.log(response);
              if (response.satusCode == 200) {
                  model.updateStatus(ID, 'done');
              } else {
                  model.updateStatus(ID, 'error');
              }
          });
  </code></pre>
  
  <p>I've tried using the https.request method but that yields the same result. I've searched the web for a solution but I came up empty handed.</p>
  
  <p>From what I can tell, it's a problem with the PFX \ P12 key which might not be so far-fetched, considering I received the key from a third-party. The only thing I can think of is converting the key format using openSSL and seeing if that works. Any suggestions or help would be greatly appreciated.</p>