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
Using out flag
import { openssl } from 'openssl-ts';
const output = await openssl(['genrsa', '-out', 'private.key', '2048']);
console.log(output.toString());
Without `out` flag
import { openssl } from 'openssl-ts';
const output = await openssl(['genrsa', '2048']);
console.log(output.toString());
Using `in` flag
import { openssl } from 'openssl-ts';
const output = await openssl(['rsa', '-in', 'private.key', '-check']);
console.log(output.toString());
Without `in` flag and using stdin
import { openssl } from 'openssl-ts';
const buffer = readFileSync('private.key');
const output = await openssl(['rsa', 'check'], {
stdin: buffer,
});
console.log(output.toString());
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.