3

I have generated certificates using below commands.

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365

And I am using it in nest js as following.

const httpsOptions = {
  key: fs.readFileSync('./secrets/key.pem'),
  cert: fs.readFileSync('./secrets/cert.pem'),
};
const app = await NestFactory.create(AppModule, {
  httpsOptions,
});
await app.listen(3000);

And I am getting below error. What wrong am I doing here?

(node:4868) UnhandledPromiseRejectionWarning: Error: error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt
    at Object.createSecureContext (_tls_common.js:149:17)
    at Server.setSecureContext (_tls_wrap.js:1323:27)
    at Server (_tls_wrap.js:1181:8)
    at new Server (https.js:66:14)
    at Object.createServer (https.js:91:10)
    at ExpressAdapter.initHttpServer (C:\my-project\node_modules\@nestjs\platform-express\adapters\express-adapter.js:97:37)
    at NestApplication.createServer (C:\my-project\node_modules\@nestjs\core\nest-application.js:68:26)
    at NestApplication.registerHttpServer (C:\my-project\node_modules\@nestjs\core\nest-application.js:51:32)
    at new NestApplication (C:\my-project\node_modules\@nestjs\core\nest-application.js:35:14)
    at NestFactoryStatic.create (C:\my-project\node_modules\@nestjs\core\nest-factory.js:35:26)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at bootstrap (C:\my-project\server\main.ts:25:18)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:4868) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 9)
(node:4868) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Anonymous Creator
  • 2,968
  • 7
  • 31
  • 77

1 Answers1

3

When I generated certificates differently, it started working. I used below to generate certificate.

openssl req -newkey rsa:2048 -new -nodes -keyout key.pem -out csr.pem
openssl x509 -req -days 365 -in csr.pem -signkey key.pem -out server.crt

And used it as below.

var options = {
      key: fs.readFileSync('./key.pem', 'utf8'),
      cert: fs.readFileSync('./server.crt', 'utf8')
   };

Source: https://stackoverflow.com/a/24283204/9263418

Anonymous Creator
  • 2,968
  • 7
  • 31
  • 77