Skip to content

unityaisolutions/openssl-web-js

Repository files navigation

OpenSSL-WASM-JS

A minimal JavaScript and WebAssembly port of OpenSSL for web browsers.

Overview

OpenSSL-WASM-JS provides a lightweight, browser-compatible implementation of OpenSSL cryptographic functions through WebAssembly. This library enables secure cryptographic operations directly in the browser with performance close to native code.

Features

  • Lightweight: Minimized JavaScript wrapper with optimized WebAssembly binary
  • Comprehensive: Supports essential OpenSSL cryptographic functions
  • Browser-compatible: Works in all modern browsers that support WebAssembly
  • Easy to use: Simple JavaScript API for common cryptographic operations
  • Secure: Preserves the security properties of OpenSSL

Installation

For Users

npm install openssl-wasm-js

Or include directly in your HTML:

<script src="https://cdn.example.com/openssl-wasm-js/dist/openssl.min.js"></script>

For Developers

To set up the development environment:

# Clone the repository
git clone https://github.com/yourusername/openssl-wasm-js.git
cd openssl-wasm-js

# Run the automated setup script
npm run setup

# Or set up manually
npm install

See the Setup Guide for detailed instructions.

Usage

// Basic usage
const opensslWasm = await OpenSSLWasm.initialize();

// Generate a random key
const key = opensslWasm.randomBytes(32);

// AES encryption
const encrypted = opensslWasm.aesEncrypt(data, key, iv);

// SHA-256 hash
const hash = opensslWasm.sha256(data);

// RSA operations
const { publicKey, privateKey } = opensslWasm.generateRsaKeyPair(2048);
const signature = opensslWasm.rsaSign(data, privateKey);
const isValid = opensslWasm.rsaVerify(data, signature, publicKey);

See the documentation for complete API details and the examples directory for more usage examples.

Building from Source

Prerequisites

  • Node.js (v14+)
  • Emscripten SDK (we include it as a submodule)
  • CMake (3.14+)
  • Python (3.6+)

Build Steps

  1. Clone the repository:

    git clone https://github.com/yourusername/openssl-wasm-js.git
    cd openssl-wasm-js
  2. Install dependencies:

    npm install
  3. Build the project:

    npm run build

The build process will:

  1. Download and patch OpenSSL
  2. Compile OpenSSL to WebAssembly using Emscripten
  3. Generate the JavaScript wrapper
  4. Create optimized and minified distribution files

Documentation

Examples

License

This project is licensed under the MIT License - see the LICENSE file for details.

OpenSSL is licensed under the Apache License 2.0. See OpenSSL License for details.

Acknowledgments

About

An advanced web crypto protocol using OpenSSL.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •