CodeF0x
CodeF0x

Reputation: 2682

Node.js + Express.js | Trying to set up a HTTPS server

I'm trying to setup a HTTPS server with Node.js and Express.js.

I'm currently trying:

const filesystem = require('fs');
const express = require('express');
const server = express();
const http = require('http').Server(server);
const https = require('https');
const io = require('socket.io')(http);
require('./routes')(server);
require('./chat-logic')(io);

// Dummy cert
const privateKey  = filesystem.readFileSync('cert/key.pem', 'utf8');
const certificate = filesystem.readFileSync('cert/cert.pem', 'utf8');

const credentials = {key: privateKey, cert: certificate};
const httpsServer = https.createServer(credentials, server);

server.use(express.static(__dirname + '/src'));
http.listen(3000, () => console.log('Listening on *3000'));
httpsServer.listen(3443, () => console.log('HTTPS on *3443'));

However, I get this error:

_tls_common.js:134
      c.context.setKey(key, passphrase);
                ^

Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt

What am I doing wrong here?

Upvotes: 8

Views: 8530

Answers (1)

Bmaed Riasbet
Bmaed Riasbet

Reputation: 14998

Try mention you key's passphrase in this line or provide an empty string '':

const credentials = {key: privateKey, cert: certificate, passphrase: '??'};

Upvotes: 24

Related Questions