Product
Introducing License Enforcement in Socket
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
asmcrypto.js
Advanced tools
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.
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);
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 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.
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.
JavaScript implementation of popular cryptographic utilities with performance in mind.
Add <script src="path/to/asmcrypto.js"></script>
into your page.
// Hash whole string at once
digest = asmCrypto.SHA256.hex("The quick brown fox jumps over the lazy dog");
Before you start check that npm is installed:
npm --version
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 ☺
In the development of this project, special attention was paid to the performance issues. In the result of all the optimizations made this stuff is pretty fast under Firefox and Chrome.
Secure Hash Algorithm — a cryptographic hash function with 160-bit output.
A cryptographic hash fuction with 256-bit output.
Calculates message digest of the supplied input data
(can be a binary string or ArrayBuffer
/Uint8Array
object).
Returns raw message digest as an Uint8Array
object.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates message digest of the supplied input data
(can be a binary string or ArrayBuffer
/Uint8Array
object).
Returns a string containing hex-encoded message digest.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates message digest of the supplied input data
(can be a binary string or ArrayBuffer
/Uint8Array
object).
Returns a string containing hex-encoded message digest.
Throws
TypeError
when something ridiculous is supplied as input data.Secure Hash Algorithm — a cryptographic hash functions family.
A cryptographic hash fuction with 256-bit output.
Calculates message digest of the supplied input data
(can be a binary string or ArrayBuffer
/Uint8Array
object).
Returns raw message digest as an Uint8Array
object.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates message digest of the supplied input data
(can be a binary string or ArrayBuffer
/Uint8Array
object).
Returns a string containing hex-encoded message digest.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates message digest of the supplied input data
(can be a binary string or ArrayBuffer
/Uint8Array
object).
Returns a string containing hex-encoded message digest.
Throws
TypeError
when something ridiculous is supplied as input data.A cryptographic hash function with 512-bit output.
Calculates message digest of the supplied input data
(can be a binary string or ArrayBuffer
/Uint8Array
object).
Returns raw message digest as an Uint8Array
object.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates message digest of the supplied input data
(can be a binary string or ArrayBuffer
/Uint8Array
object).
Returns a string containing hex-encoded message digest.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates message digest of the supplied input data
(can be a binary string or ArrayBuffer
/Uint8Array
object).
Returns a string containing hex-encoded message digest.
Throws
TypeError
when something ridiculous is supplied as input data.Hash-based Message Authentication Code
Used to calculate message authentication code with a cryptographic hash function in combination with a secret cryptographic key.
Calculates HMAC-SHA1 of data
with password
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Returns araw message authentication code as an Uint8Array
object.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates HMAC-SHA1 of data
with password
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Returns a string containing hex-encoded message authentication code.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates HMAC-SHA1 of data
with password
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Returns a string containing base64-encoded message authentication code.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates HMAC-SHA256 of data
with password
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Returns araw message authentication code as an Uint8Array
object.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates HMAC-SHA256 of data
with password
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Returns a string containing hex-encoded message authentication code.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates HMAC-SHA256 of data
with password
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Returns a string containing base64-encoded message authentication code.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates HMAC-SHA512 of data
with password
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Returns araw message authentication code as an Uint8Array
object.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates HMAC-SHA512 of data
with password
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Returns a string containing hex-encoded message authentication code.
Throws
TypeError
when something ridiculous is supplied as input data.Calculates HMAC-SHA512 of data
with password
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Returns a string containing base64-encoded message authentication code.
Throws
TypeError
when something ridiculous is supplied as input data.Password-Based Key Derivation Function 2
Applies a cryptographic hash function to the input password or passphrase along with a salt value and repeats the process many times to produce a derived key, which can then be used as a cryptographic key in subsequent operations. The added computational work makes password cracking much more difficult.
Derive key from the password
with salt
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Optional iterations
(number of key derivatoin rounds) and dklen
(desired key length) may be supplied.
Throws
TypeError
.The same as above except returning value type.
The same as above except returning value type.
Derive key from the password
with salt
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Optional iterations
(number of key derivatoin rounds) and dklen
(desired key length) may be supplied.
Throws
TypeError
.The same as above except returning value type.
The same as above except returning value type.
Derive key from the password
with salt
. Both can be either binary strings or Uint8Array
/ArrayBuffer
objects.
Optional iterations
(number of key derivatoin rounds) and dklen
(desired key length) may be supplied.
Throws
TypeError
.The same as above except returning value type.
The same as above except returning value type.
Advanced Encryption Standard
TODO
Cipher Block Chaining Mode.
Encrypts supplied data
with key
in CBC mode. Both can be either binary strings or Uint8Array
objects or ArrayBuffer
objects.
Optional padding
and iv
may be passed to override default settings (PKCS#7 padding is on and iv is zero-vector).
Returns encrypted data as Uint8Array
.
Decrypts supplied data
with key
in CBC mode. Both can be either binary strings or Uint8Array
objects or ArrayBuffer
objects.
Optional padding
and iv
may be passed to override default settings (PKCS#7 padding is on and iv is zero-vector).
Returns encrypted data as Uint8Array
.
Cipher Feedback Mode.
Encrypts supplied data
with key
in CFB mode. Both can be either binary strings or Uint8Array
objects or ArrayBuffer
objects.
Optional iv
may be passed to override default settings (zero-vector iv
).
Returns encrypted data as Uint8Array
.
Decrypts supplied data
with key
in CFB mode. Both can be either binary strings or Uint8Array
objects or ArrayBuffer
objects.
Optional iv
may be passed to override default settings (zero-vector iv
).
Returns encrypted data as Uint8Array
.
Output Feedback Mode.
Encrypts supplied data
with key
in OFB mode. Both can be either binary strings or Uint8Array
objects or ArrayBuffer
objects.
Optional iv
may be passed to override default settings (zero-vector iv
).
Returns encrypted data as Uint8Array
.
Decrypts supplied data
with key
in OFB mode. Both can be either binary strings or Uint8Array
objects or ArrayBuffer
objects.
Optional iv
may be passed to override default settings (zero-vector iv
).
Returns encrypted data as Uint8Array
.
TODO
Counter with CBC-MAC mode.
Due to JS limitations (counter is 32-bit unsigned) maximum encrypted message length is limited to near 64 GiB ( 2^36 - 16 ) per nonce
-key
pair.
Additional authenticated data adata
maximum length is limited to 65279 bytes ( 2^16 - 2^8 ),
wich is considered enough for the most of use-cases.
Optional tagSize
, the size of the authentication tag, may be 4, 6, 8, 12, 16 (default).
Keep in mind that same nonce must not be used more than once with the same key.
Encrypts supplied data
with key
-nonce
in CCM mode.
Returns encrypted data as Uint8Array
.
Decrypts supplied data
with key
-nonce
in CCM mode.
Returns encrypted data as Uint8Array
.
TODO
Generate RSA private key of bitlen
length along with the public exponent pubexp
.
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
TODO
ISAAC-based CSPRG
Drop-in replacement for window.crypto.getRandomValues
Perform PRNG seeding.
Allow implicitly-only seeded random output.
Disable implicit seeding warning when it's not desirable, e.g. at a unit test run.
Not yet implemented:
FAQs
Asm.js implementation of WebCrypto API
The npm package asmcrypto.js receives a total of 115,421 weekly downloads. As such, asmcrypto.js popularity was classified as popular.
We found that asmcrypto.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Ensure open-source compliance with Socket’s License Enforcement Beta. Set up your License Policy and secure your software!
Product
We're launching a new set of license analysis and compliance features for analyzing, managing, and complying with licenses across a range of supported languages and ecosystems.
Product
We're excited to introduce Socket Optimize, a powerful CLI command to secure open source dependencies with tested, optimized package overrides.