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

soft-aes-wasm

v0.2.2

Published

A Wasm Interface for AES.

Downloads

14

Readme

soft-aes-wasm

This project provides a WebAssembly (Wasm) interface for the soft-aes Rust library, allowing for AES encryption and decryption directly in web applications. It includes support for AES ECB and AES CBC modes and integrated Cipher-based Message Authentication Code (AES-CMAC) calculation.

The library includes support for PKCS#7 padding and 0x80 padding (ISO/IEC 9797-1 Padding Method 2).

IMPORTANT: This implementation currently does not incorporate defenses against side-channel attacks. Consequently, Soft-AES is optimally positioned for educational purposes and non-critical application scenarios where such advanced protections are not a primary concern.

Table of Contents

Installation with npm

To integrate soft-aes-wasm in your web project using npm, follow these steps:

  1. Add the soft-aes-wasm package to your project:

    npm install soft-aes-wasm
  2. Import and initialize the module in your custom JavaScript file:

    import init, {
       wasm_aes_enc_ecb,
       wasm_aes_dec_ecb,
       wasm_aes_enc_cbc,
       wasm_aes_dec_cbc,
       wasm_aes_cmac
     } from "path/to/pkg/soft_aes_wasm.js";
    
    async function run() {
        await init(); // Initialize the wasm module
    
        // Implement your AES logic here...
    }
    
    run();

Building from Source

If you want to build the Wasm module from the source, clone the repository and run wasm-pack:

git clone https://github.com/5n00py/soft-aes-wasm.git
cd soft-aes-wasm
wasm-pack build --target web

Usage

This is a basic example of how to use the AES ECB and CBC functions:

// AES ECB
const plaintext = new TextEncoder().encode("Example plaintext.");
const key = new TextEncoder().encode("Very secret key.");
const encryptedEcb = wasm_aes_enc_ecb(plaintext, key, "PKCS7");
const decryptedEcb = wasm_aes_dec_ecb(encryptedEcb, key, "PKCS7");

// AES CBC
const key = new TextEncoder().encode("Very secret key.");
const iv = new TextEncoder().encode("Random Init Vec.");
const encryptedCbc = wasm_aes_enc_cbc(plaintext, key, iv, "PKCS7");
const decryptedCbc = wasm_aes_dec_cbc(encryptedCbc, key, iv, "PKCS7");

Notes:

  • plaintext should be a Uint8Array.
  • key should be a Uint8Array of 16 bytes (AES-128), 24 bytes (AES-192), or 32 bytes (AES-256).
  • iv for AES CBC should be a 16-byte Uint8Array.

In the example above a 16-byte key is used to demonstrate AES-128. Changing the key length to 24 or 32 bytes will use AES-192 or AES-256 respectively. The IV for AES CBC must always be 16 bytes regardless of the AES variant.

Test

To run tests, clone the project form github and build from source as described above. Navigate to the root folder and start a local server, e.g.:

python3 -m http.server

Open your browser and go to http://localhost:8000/test/index.html to see the test results.

Related Projects

soft-aes

The core Rust library on which this project relies is soft-aes.

Web UI

For a practical and user-friendly integration of this library in the browser visit AES-Wasm Tool.

License

Copyright David Schmid ([email protected])

Binaries are subject to the terms of the GPL-3.0 License - see the LICENSE file for details.