npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

openssl-ts

v1.0.4

Published

An openssl wrapper written in TypeScript

Downloads

697

Readme

build License: MIT Coverage Status node-current npm type definitions current-version

Openssl Ts

Openssl-ts is a modern openssl wrapper written in typescript with 0 dependencies.

This library is not responsible of doing any filesystem operations (read/write). It just handles the openssl calls.

Output from openssl should be handled by the caller (you).

This project has been testing with Node >= v8.17 and with openssl >= 1.1.1m

Installation

Using npm:

npm install openssl-ts

or using the Yarn package manager:

yarn add openssl-ts

Usage

The signature is pretty simple:

First parameter is an array of strings (openssl arguments). The second parameter is an optional object with the following properties:

  • opensslPath: path to the openssl executable.

    You can override this by using the OPENSSL_PATH environment variable as well.

    Default: openssl (must be in the PATH)

  • stdin: buffer to be passed to openssl as stdin

    This would be like using cat and piping the input to openssl.

    example: cat private.key | openssl rsa -check

    Why would you want to do this? Simple, sometimes you have the content already on ram and you want to pass it to openssl without the need to first write it to a file.

    Notice: cat is not being used to pipe the input to openssl.

Examples

import { openssl } from 'openssl-ts';

const output = await openssl(['genrsa', '-out', 'private.key', '2048']);

// output is a Buffer
console.log(output.toString());
/*
Generating RSA private key, 2048 bit long modulus (2 primes)
................................................+++++
...........+++++
e is 65537 (0x010001)
*/
// if you want the private.key content, you should read the file from the filesystem
import { openssl } from 'openssl-ts';

const output = await openssl(['genrsa', '2048']);

// output is a Buffer
console.log(output.toString());

/*
Generating RSA private key, 2048 bit long modulus (2 primes)
....................................................................+++++
.............................+++++
e is 65537 (0x010001)
-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEAoNKO2MDD9TzZ9KpSJ7JAuIWDhTY5qZJGbgUltnUKqTts+A7s
...
-----END RSA PRIVATE KEY-----
*/

// if you want just the key you must parse the output
import { openssl } from 'openssl-ts';

const output = await openssl(['rsa', '-in', 'private.key', '-check']);

// output is a Buffer
console.log(output.toString());


/*
RSA key ok
writing RSA key
-----BEGIN RSA PRIVATE KEY-----
....
-----END RSA PRIVATE KEY-----

*/
import { openssl } from 'openssl-ts';

const buffer = readFileSync('private.key');

const output = await openssl(['rsa', 'check'], {
  stdin: buffer,
});

// output is a Buffer
console.log(output.toString());

/*
RSA key ok
writing RSA key
-----BEGIN RSA PRIVATE KEY-----
....
-----END RSA PRIVATE KEY-----

*/

Tests

Running all test:

yarn test

Running with coverage:

yarn test:cov

Debugging

You can use the NODE_DEBUG environment variable to enable debugging.

Example:

NODE_DEBUG=openssl node yourscript.js

This will print the openssl command that will be executed and its parameters.