LICENSE: Apache 2.0
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.
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");
})();
OpenSSL.js is available through npm
npm install openssl.js
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 BrowserFSrootDir
: 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.
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");
})();
import { OpenSSL } from "../dist/browser.openssl.js";
/** @wasmer/wasmfs */
import WasmFs from "./wasmfs.esm.js";
const wasmFs = new WasmFs();
(async function() {
let openSSL = new OpenSSL({
fs: wasmFs.fs,
rootDir: "/",
wasmBinaryPath: "../dist/openssl.wasm"
});
let result1 = await openSSL.runCommand(
"genpkey -algorithm Ed25519 -out /private.pem"
);
let pK = wasmFs.fs.readFileSync("/private.pem", { encoding: "utf8" });
console.log(pK);
document.body.innerText = pK;
})();