What is asmcrypto.js?
asmcrypto.js is a JavaScript library that provides cryptographic algorithms implemented in WebAssembly and JavaScript. It aims to offer high-performance cryptographic operations for web applications.
What are asmcrypto.js's main functionalities?
Hashing
This feature allows you to perform hashing operations. The example demonstrates how to compute the SHA-256 hash of a string.
const asmCrypto = require('asmcrypto.js');
const hash = asmCrypto.SHA256.hex('Hello, World!');
console.log(hash);
Symmetric Encryption
This feature allows you to perform symmetric encryption using algorithms like AES. The example shows how to encrypt a string using AES-CBC.
const asmCrypto = require('asmcrypto.js');
const key = asmCrypto.AES_CBC.generateKey(16);
const encrypted = asmCrypto.AES_CBC.encrypt(asmCrypto.string_to_bytes('Hello, World!'), key);
console.log(encrypted);
Asymmetric Encryption
This feature allows you to perform asymmetric encryption using algorithms like RSA. The example demonstrates how to encrypt a string using RSA.
const asmCrypto = require('asmcrypto.js');
const keyPair = asmCrypto.RSA.generateKey(1024);
const encrypted = asmCrypto.RSA.encrypt(asmCrypto.string_to_bytes('Hello, World!'), keyPair.publicKey);
console.log(encrypted);
Digital Signatures
This feature allows you to create digital signatures. The example shows how to sign a string using RSA.
const asmCrypto = require('asmcrypto.js');
const keyPair = asmCrypto.RSA.generateKey(1024);
const signature = asmCrypto.RSA.sign(asmCrypto.string_to_bytes('Hello, World!'), keyPair.privateKey);
console.log(signature);
Other packages similar to asmcrypto.js
crypto-js
crypto-js is a widely-used library that provides standard and secure cryptographic algorithms implemented in JavaScript. It is known for its ease of use and comprehensive documentation. Compared to asmcrypto.js, crypto-js does not utilize WebAssembly for performance optimization.
node-forge
node-forge is a robust library that offers a wide range of cryptographic operations, including SSL/TLS, PKI, and more. It is highly versatile and suitable for both client-side and server-side applications. Unlike asmcrypto.js, node-forge is purely JavaScript-based and does not leverage WebAssembly.
sjcl
Stanford JavaScript Crypto Library (sjcl) is a compact, fast, and secure cryptographic library. It is designed to be easy to use and includes a variety of cryptographic primitives. While sjcl is efficient, it does not use WebAssembly for performance enhancements like asmcrypto.js.
asmCrypto
JavaScript implementation of popular cryptographic utilities with performance in mind.
Build & Test
Then download and build the stuff:
git clone https://github.com/asmcrypto/asmcrypto.js.git
cd asmcrypto.js/
npm install
Running tests is always a good idea:
npm test
Congratulations! Now you have your asmcrypto.js
ready to use ☺
Support
- NodeJS 10
- IE11
- last two Chrome versions
- last two Firefox versions and the latest Firefox ESR
- last two Edge versions
- last two Safari versions
AsmCrypto 2.0
- Moved to TypeScript
- I have no confident knowledge on random generation, so I don't feel right maintaining it. As of 2.0 all custom random generation and seeding code is removed, the underlying browsers and environments have to provide secure random.