Openssl and nodejs

This an awesome post for openssl public key private key
http://www.devco.net/archives/2006/02/13/public_-_private_key_encryption_using_openssl.php
Here is the post for openssl certificate
http://www.thegeekstuff.com/2009/07/linux-apache-mod-ssl-generate-key-csr-crt-file/

At first generate ssl using openssl

1. Create a private key

$openssl genrsa 1024 > server.key

2. Create a Certificate Signing Request

$openssl req -new -key server.key -out server.csr

3. Create a ssl certificate

$openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

Now use this code to run in node.js

var https = require('https');
var fs = require('fs');

// This line is from the Node.js HTTPS documentation.
var options = {
  key: fs.readFileSync('server.key'),
  cert: fs.readFileSync('server.crt')
};


https.createServer(options, function (req, res) {
  res.writeHead(200);
  res.end("hello world\n");
}).listen(8000);

save file as server.js.

Now run

$node server.js

open browser, hit:

https://localhost:8000
Advertisements
Openssl and nodejs

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s