Socket
Socket
Sign inDemoInstall

pem

Package Overview
Dependencies
3
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

pem


Version published
Weekly downloads
244K
decreased by-15.34%
Maintainers
2
Created
Weekly downloads
 

Package description

What is pem?

The 'pem' npm package is a tool for creating and managing PEM (Privacy Enhanced Mail) files, which are commonly used for SSL/TLS certificates and keys. It provides a variety of functionalities for generating, reading, and managing these files.

What are pem's main functionalities?

Generate SSL Certificates

This feature allows you to generate self-signed SSL certificates. The code sample demonstrates how to create a certificate that is valid for one day.

const pem = require('pem');
pem.createCertificate({ days: 1, selfSigned: true }, function (err, keys) {
  if (err) {
    throw err;
  }
  console.log(keys);
});

Read Certificate Information

This feature allows you to read and extract information from an existing certificate. The code sample shows how to read certificate information from a specified file path.

const pem = require('pem');
pem.readCertificateInfo('path/to/certificate.pem', function (err, info) {
  if (err) {
    throw err;
  }
  console.log(info);
});

Create Certificate Signing Request (CSR)

This feature allows you to create a Certificate Signing Request (CSR), which is used to request a certificate from a Certificate Authority (CA). The code sample demonstrates how to create a CSR with a specified common name.

const pem = require('pem');
pem.createCSR({ commonName: 'example.com' }, function (err, csr) {
  if (err) {
    throw err;
  }
  console.log(csr);
});

Create Private Key

This feature allows you to generate a private key. The code sample shows how to create a private key using the 'pem' package.

const pem = require('pem');
pem.createPrivateKey(function (err, key) {
  if (err) {
    throw err;
  }
  console.log(key);
});

Other packages similar to pem

Changelog

Source

v1.12.8

11 September 2018

  • chore(package): dep updates and changelog 98a63c9
  • fix(pem): allow utf8 charset in fields 2cb97aa
  • fix(package): dep updates and fix deprecated api 610a403

Readme

Source

pem

Create private keys and certificates with node.js

Build Status npm version npm downloads pem documentation Greenkeeper badge

JavaScript Style Guide

Installation

Install with npm

npm install pem

Examples

Here are some examples for creating an SSL key/cert on the fly, and running an HTTPS server on port 443. 443 is the standard HTTPS port, but requires root permissions on most systems. To get around this, you could use a higher port number, like 4300, and use https://localhost:4300 to access your server.

Basic https

var https = require('https')
var pem = require('pem')

pem.createCertificate({ days: 1, selfSigned: true }, function (err, keys) {
  if (err) {
    throw err
  }
  https.createServer({ key: keys.serviceKey, cert: keys.certificate }, function (req, res) {
    res.end('o hai!')
  }).listen(443)
})

Express

var https = require('https')
var pem = require('pem')
var express = require('express')

pem.createCertificate({ days: 1, selfSigned: true }, function (err, keys) {
  if (err) {
    throw err
  }
  var app = express()

  app.get('/', function (req, res) {
    res.send('o hai!')
  })

  https.createServer({ key: keys.serviceKey, cert: keys.certificate }, app).listen(443)
})

API

Please have a look into the API documentation.

we had to clean up a bit

Custom extensions config file

You can specify custom OpenSSL extensions using the config or extFile options for createCertificate (or using csrConfigFile with createCSR).

extFile and csrConfigFile should be paths to the extension files. While config will generate a temporary file from the supplied file contents.

If you specify config then the v3_req section of your config file will be used.

The following would be an example of a Certificate Authority extensions file:

[req]
req_extensions = v3_req
distinguished_name = req_distinguished_name

[req_distinguished_name]
commonName = Common Name
commonName_max = 64

[v3_req]
basicConstraints = critical,CA:TRUE

While the following would specify subjectAltNames in the resulting certificate:

[req]
req_extensions = v3_req

[ v3_req ]
basicConstraints = CA:FALSE
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
subjectAltName = @alt_names

[alt_names]
DNS.1 = host1.example.com
DNS.2 = host2.example.com
DNS.3 = host3.example.com

Note that createCertificate and createCSR supports the altNames option which would be easier to use in most cases.

Warning: If you specify altNames the custom extensions file will not be passed to OpenSSL.

Setting openssl location

In some systems the openssl executable might not be available by the default name or it is not included in $PATH. In this case you can define the location of the executable yourself as a one time action after you have loaded the pem module:

var pem = require('pem')
pem.config({
  pathOpenSSL: '/usr/local/bin/openssl'
})
// do something with the pem module

Specialthanks to

  • Andris Reinman (@andris9) - Initiator of pem

License

MIT

FAQs

Last updated on 11 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc