A WebAssembly port of OpenSSL for node and the browser.

This is a source-code build of OpenSSL using the wasienv toolchain. The test suite is still under development. Until it is complete, the author makes no claims concerning accuracy or security. Use at your own risk.

Quick Start

ES6 Module (main)

import { OpenSSL } from " ../dist/openssl.js " ; import { fileURLToPath } from " url " ; import { dirname } from " path " ; import path from " path " ; import fs from " fs " ; const __filename = fileURLToPath ( import .meta.url) ; const __dirname = dirname ( __filename ) ; ( async function ( ) { let rootDir = path . resolve ( __dirname , " ./sandbox " ) ; let openSSL = new OpenSSL ( { fs , rootDir } ) ; let result1 = await openSSL . runCommand ( " genrsa -out /private.pem " ) ; let result2 = await openSSL . runCommand ( " rsa -in /private.pem -pubout " ) ; } ) ( ) ;

Installation

OpenSSL.js is available through npm

npm install openssl.js

Usage

The main export exposes the OpenSSL class; the constructor takes two arguments in an args object:

fs : Use either the node builtin fs or an API compatible version like @wasmer/wasmfs (which uses memfs), or BrowserFS

: Use either the node builtin fs or an API compatible version like @wasmer/wasmfs (which uses memfs), or BrowserFS rootDir : The path in the file system to map to the root ( / ) of the OpenSSL.js instance to use for file IO

The instance exposes a single method, runCommand , which accepts a string containing commands to be run against the OpenSSL command line interface.

Examples

CJS

const { OpenSSL } = require ( ' ../dist/openssl.cjs ' ) ; const { resolve } = require ( ' path ' ) ; const fs = require ( ' fs ' ) ; ( async function ( ) { let rootDir = resolve ( __dirname , " ./sandbox " ) ; let openSSL = new OpenSSL ( { fs , rootDir } ) ; let result1 = await openSSL . runCommand ( " genrsa -out /private.pem " ) ; let result2 = await openSSL . runCommand ( " rsa -in /private.pem -pubout " ) ; } ) ( ) ;

Browser