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

@originjs/crypto-js-wasm

v1.1.1

Published

An alternative to crypto-js implemented with WebAssembly and ESM

Downloads

448

Readme

@originjs/crypto-js-wasm

English | 中文


crypto-js-wasm is a javascript library of crypto standards. Inspired by crypto-js, but now powered by WebAssembly.

  • Safe: The process of encryption is fully enclosed and invisible thanks to WebAssembly
  • Efficient: Up to 16x faster than crypto-js (see Benchmark)
  • Compatible: Has the same API with crypto-js
  • Browser & Nodejs: Support both browser and nodejs
  • Versatile: 15+ crypto standards supported, including MD5, SHA-x, AES, RC4, etc
  • ESM: Written in ESM, build as UMD for compatibility

What's new

We have supported RSA and TypeScript now!

Getting started

npm install @originjs/crypto-js-wasm

or

pnpm install @originjs/crypto-js-wasm

or

yarn add @originjs/crypto-js-wasm

Usage

Note that the async function loadWasm() should be called once (and once only!) for each algorithm that will be used, unless loadAllWasm() is called at the very beginning.

import CryptoJSW from '@originjs/crypto-js-wasm';

// (Optional) load all wasm files
await CryptoJSW.loadAllWasm();

// Async/Await syntax
await CryptoJSW.MD5.loadWasm();
const rstMD5 = CryptoJSW.MD5('message').toString();
console.log(rstMD5);

// Promise syntax
CryptoJSW.SHA256.loadWasm().then(() => {
    const rstSHA256 = CryptoJSW.SHA256('message').toString();
    console.log(rstSHA256);
})

Please note that HMAC does not have a loadWasm, as a hasher must be specified if you want to use HMAC (i.e. HmacSHA1).

And the loadWasm in pbkdf2 only calls SHA1.loadWasm as SHA1 is the default hasher of pbkdf2. If you specified another hasher, the corresponding loadWasm of the hasher should be called repectly. Same case in evpkdf/MD5 as MD5 is the default hasher of evpkdf.

Usage of RSA

Please refer to this document.

Available standards

  • MD5 / HmacMD5
  • SHA1 / HmacSHA1
  • SHA224 / HmacSHA224
  • SHA256 / HmacSHA256
  • SHA384 / HmacSHA384
  • SHA512 / HmacSHA512
  • SHA3 / HmacSHA3
  • RIPEMD160 / HmacRIPEMD160
  • PBKDF2
  • EvpKDF
  • AES
  • Blowfish
  • DES
  • TripleDES
  • Rabbit
  • RabbitLegacy
  • RC4
  • RC4Drop
  • RSA

Benchmark

The benchmark below is run on a desktop PC (i5-4590, 16 GB RAM, Windows 10 Version 21H2 (OSBuild 19044, 1466)).

Chrome 102.0.5005.63:

benchmark_chrome

Firefox 101.0:

benchmark_firefox

Nodejs v16.6.4:

nodejs

RSA(vs jsencrypt) in Chrome:

rsa_chrome

Development

# install dependencies
pnpm install

# build for production
pnpm run build

# run all tests
pnpm run test

# run all tests with coverage
pnpm run coverage

Why do we need an async loadWasm call?

This is because the WebAssembly binary needs to be load by WebAssembly.instantiate, and it is async.

The async WebAssembly.instantiate is recommended instead of its sync variant WebAssembly.instance, and in many cases the WebAssembly.instance can not load WebAssembly binary whose size is not small enough.

Why do we store wasm binaries in base64-encoded chars?

This is because crypto-js-wasm may be used in browser or nodejs. This is relative elegant implementation comparing with wasm loader in browser(powered by webpack, vite or something else) or fs in nodejs.

License

Distributed under the Mulan Permissive Software License