0

I am trying to add a certificate to my Nodejs Express Service to get HTTPS working. I followed this answer to start with: Enabling HTTPS on express.js

Although I only have .cer and .txt (my key) files, so I just manually renamed the .txt to .key. I then changed the lines in the above answer to this:

-- HIS ANSWER:
var privateKey  = fs.readFileSync('sslcert/server.key', 'utf8');
var certificate = fs.readFileSync('sslcert/server.crt', 'utf8');

-- MY CHANGE:
var privateKey  = fs.readFileSync('server.key', 'utf8');
var certificate = fs.readFileSync('server.cer', 'utf8');

My .cer looks like this:

-----BEGIN PKCS7-----
JHfw2AWawdDH...
...hd8h28HDFWA
-----END PKCS7-----

My .key looks like this:

-----BEGIN NEW CERTIFICATE REQUEST-----
HDW28HD82HD2...
...82FHJD12
-----END NEW CERTIFICATE REQUEST-----

But when I start my service, the line var httpsServer = https.createServer(credentials, app); throws this error:

      c.context.setCert(cert);
                ^

Error: error:0906D06C:PEM routines:PEM_read_bio:no start line

I have tried many other answers to this questions but I am still not getting it to work. I have little knowledge about certificates and HTTPS so any explanations will help a lot :)

Paul Kruger
  • 2,094
  • 7
  • 22
  • 49

0 Answers0