crypto-js vs bcrypt vs node-forge vs sjcl
Cryptography Libraries for JavaScript
crypto-jsbcryptnode-forgesjclSimilar Packages:

Cryptography Libraries for JavaScript

Cryptography libraries in JavaScript provide essential tools for securing data through encryption, hashing, and other cryptographic functions. These libraries are crucial for protecting sensitive information, ensuring data integrity, and facilitating secure communications in web applications. Each library has its own strengths and use cases, making it important for developers to choose the right one based on their specific requirements, such as performance, ease of use, and the type of cryptographic operations needed.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
crypto-js13,982,95616,392487 kB2752 years agoMIT
bcrypt07,7771.11 MB3010 months agoMIT
node-forge05,2741.64 MB4583 months ago(BSD-3-Clause OR GPL-2.0)
sjcl07,230-1177 years ago(BSD-2-Clause OR GPL-2.0-only)

Feature Comparison: crypto-js vs bcrypt vs node-forge vs sjcl

Password Hashing

  • crypto-js:

    crypto-js does not specialize in password hashing but provides various hashing algorithms. However, it lacks the built-in salting and adaptive features that bcrypt offers, making it less suitable for password storage.

  • bcrypt:

    bcrypt is specifically designed for hashing passwords securely. It incorporates a salt to guard against rainbow table attacks and uses a work factor to make the hashing process slower, which helps mitigate brute-force attacks.

  • node-forge:

    node-forge does not focus on password hashing but offers hashing functions that can be used for other purposes, such as data integrity verification. It is not optimized for password security like bcrypt.

  • sjcl:

    sjcl provides hashing functions but is not specifically tailored for password hashing. It is more focused on performance and efficiency rather than security features like salting.

Encryption Algorithms

  • crypto-js:

    crypto-js offers a wide variety of encryption algorithms, including AES, DES, and Triple DES. This makes it versatile for applications needing data encryption and decryption functionalities.

  • bcrypt:

    bcrypt does not provide encryption capabilities; it is solely focused on hashing passwords. It is not suitable for encrypting data or messages.

  • node-forge:

    node-forge supports multiple encryption algorithms and is capable of handling complex cryptographic tasks, including asymmetric encryption, making it suitable for secure communications and data protection.

  • sjcl:

    sjcl provides a set of encryption algorithms, primarily focusing on performance. It is lightweight and efficient, making it ideal for applications that require fast encryption and decryption.

Performance

  • crypto-js:

    crypto-js is designed for performance and offers fast encryption and hashing operations. It is suitable for applications that require quick cryptographic functions without compromising too much on security.

  • bcrypt:

    bcrypt is slower than other hashing algorithms due to its adaptive nature, which is a deliberate design choice to enhance security. This may not be suitable for applications requiring high-speed hashing but is ideal for password storage.

  • node-forge:

    node-forge balances performance and functionality, providing efficient cryptographic operations while supporting a wide range of algorithms. It is suitable for applications needing both speed and comprehensive cryptographic capabilities.

  • sjcl:

    sjcl is optimized for performance, making it one of the fastest libraries for encryption and decryption. It is particularly useful in scenarios where speed is critical, such as in-browser applications.

Ease of Use

  • crypto-js:

    crypto-js has a simple and intuitive API, making it easy to integrate various cryptographic functions into applications. Its wide range of algorithms allows developers to choose the right one for their needs without much complexity.

  • bcrypt:

    bcrypt has a straightforward API for hashing and verifying passwords, making it easy to implement in applications. However, its focus on security may require developers to understand its parameters for optimal use.

  • node-forge:

    node-forge has a more complex API due to its comprehensive feature set. While it offers powerful capabilities, it may have a steeper learning curve for developers unfamiliar with cryptographic concepts.

  • sjcl:

    sjcl is designed to be lightweight and easy to use, with a clear API. It is suitable for developers looking for a quick and efficient way to implement cryptographic functions without extensive overhead.

Community and Support

  • crypto-js:

    crypto-js has a large user base and good community support, with plenty of examples and documentation available. It is a well-established library for cryptographic functions in JavaScript.

  • bcrypt:

    bcrypt is widely used and has a strong community, providing ample resources and documentation for developers. Its popularity ensures that it is well-maintained and regularly updated.

  • node-forge:

    node-forge has a dedicated community and is actively maintained. It offers comprehensive documentation, making it easier for developers to implement complex cryptographic tasks.

  • sjcl:

    sjcl is less popular compared to other libraries, which may result in fewer resources and community support. However, it is still maintained and has enough documentation for basic use cases.

How to Choose: crypto-js vs bcrypt vs node-forge vs sjcl

  • crypto-js:

    Select crypto-js for a wide range of cryptographic algorithms, including hashing, encryption, and decryption. It is suitable for applications that require various cryptographic functions and is easy to integrate into existing projects.

  • bcrypt:

    Choose bcrypt if you need to securely hash passwords with a strong emphasis on security and resistance to brute-force attacks. It is specifically designed for password hashing and includes built-in salting and adaptive hashing features.

  • node-forge:

    Opt for node-forge if you need a comprehensive library that supports both client-side and server-side cryptography. It is particularly useful for working with X.509 certificates, PKI, and TLS, making it ideal for secure communications.

  • sjcl:

    Use sjcl for a lightweight and efficient library that focuses on performance and ease of use. It is well-suited for applications that require fast encryption and decryption without the overhead of larger libraries.

README for crypto-js

crypto-js

JavaScript library of crypto standards.

Discontinued

Active development of CryptoJS has been discontinued. This library is no longer maintained.

Nowadays, NodeJS and modern browsers have a native Crypto module. The latest version of CryptoJS already uses the native Crypto module for random number generation, since Math.random() is not crypto-safe. Further development of CryptoJS would result in it only being a wrapper of native Crypto. Therefore, development and maintenance has been discontinued, it is time to go for the native crypto module.

Node.js (Install)

Requirements:

  • Node.js
  • npm (Node.js package manager)
npm install crypto-js

Usage

ES6 import for typical API call signing use case:

import sha256 from 'crypto-js/sha256';
import hmacSHA512 from 'crypto-js/hmac-sha512';
import Base64 from 'crypto-js/enc-base64';

const message, nonce, path, privateKey; // ...
const hashDigest = sha256(nonce + message);
const hmacDigest = Base64.stringify(hmacSHA512(path + hashDigest, privateKey));

Modular include:

var AES = require("crypto-js/aes");
var SHA256 = require("crypto-js/sha256");
...
console.log(SHA256("Message"));

Including all libraries, for access to extra methods:

var CryptoJS = require("crypto-js");
console.log(CryptoJS.HmacSHA1("Message", "Key"));

Client (browser)

Requirements:

  • Node.js
  • Bower (package manager for frontend)
bower install crypto-js

Usage

Modular include:

require.config({
    packages: [
        {
            name: 'crypto-js',
            location: 'path-to/bower_components/crypto-js',
            main: 'index'
        }
    ]
});

require(["crypto-js/aes", "crypto-js/sha256"], function (AES, SHA256) {
    console.log(SHA256("Message"));
});

Including all libraries, for access to extra methods:

// Above-mentioned will work or use this simple form
require.config({
    paths: {
        'crypto-js': 'path-to/bower_components/crypto-js/crypto-js'
    }
});

require(["crypto-js"], function (CryptoJS) {
    console.log(CryptoJS.HmacSHA1("Message", "Key"));
});

Usage without RequireJS

<script type="text/javascript" src="path-to/bower_components/crypto-js/crypto-js.js"></script>
<script type="text/javascript">
    var encrypted = CryptoJS.AES(...);
    var encrypted = CryptoJS.SHA256(...);
</script>

API

See: https://cryptojs.gitbook.io/docs/

AES Encryption

Plain text encryption

var CryptoJS = require("crypto-js");

// Encrypt
var ciphertext = CryptoJS.AES.encrypt('my message', 'secret key 123').toString();

// Decrypt
var bytes  = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
var originalText = bytes.toString(CryptoJS.enc.Utf8);

console.log(originalText); // 'my message'

Object encryption

var CryptoJS = require("crypto-js");

var data = [{id: 1}, {id: 2}]

// Encrypt
var ciphertext = CryptoJS.AES.encrypt(JSON.stringify(data), 'secret key 123').toString();

// Decrypt
var bytes  = CryptoJS.AES.decrypt(ciphertext, 'secret key 123');
var decryptedData = JSON.parse(bytes.toString(CryptoJS.enc.Utf8));

console.log(decryptedData); // [{id: 1}, {id: 2}]

List of modules

  • crypto-js/core
  • crypto-js/x64-core
  • crypto-js/lib-typedarrays

  • crypto-js/md5
  • crypto-js/sha1
  • crypto-js/sha256
  • crypto-js/sha224
  • crypto-js/sha512
  • crypto-js/sha384
  • crypto-js/sha3
  • crypto-js/ripemd160

  • crypto-js/hmac-md5
  • crypto-js/hmac-sha1
  • crypto-js/hmac-sha256
  • crypto-js/hmac-sha224
  • crypto-js/hmac-sha512
  • crypto-js/hmac-sha384
  • crypto-js/hmac-sha3
  • crypto-js/hmac-ripemd160

  • crypto-js/pbkdf2

  • crypto-js/aes
  • crypto-js/tripledes
  • crypto-js/rc4
  • crypto-js/rabbit
  • crypto-js/rabbit-legacy
  • crypto-js/evpkdf

  • crypto-js/format-openssl
  • crypto-js/format-hex

  • crypto-js/enc-latin1
  • crypto-js/enc-utf8
  • crypto-js/enc-hex
  • crypto-js/enc-utf16
  • crypto-js/enc-base64

  • crypto-js/mode-cfb
  • crypto-js/mode-ctr
  • crypto-js/mode-ctr-gladman
  • crypto-js/mode-ofb
  • crypto-js/mode-ecb

  • crypto-js/pad-pkcs7
  • crypto-js/pad-ansix923
  • crypto-js/pad-iso10126
  • crypto-js/pad-iso97971
  • crypto-js/pad-zeropadding
  • crypto-js/pad-nopadding

Release notes

4.2.0

Change default hash algorithm and iteration's for PBKDF2 to prevent weak security by using the default configuration.

Custom KDF Hasher

Blowfish support

4.1.1

Fix module order in bundled release.

Include the browser field in the released package.json.

4.1.0

Added url safe variant of base64 encoding. 357

Avoid webpack to add crypto-browser package. 364

4.0.0

This is an update including breaking changes for some environments.

In this version Math.random() has been replaced by the random methods of the native crypto module.

For this reason CryptoJS might not run in some JavaScript environments without native crypto module. Such as IE 10 or before or React Native.

3.3.0

Rollback, 3.3.0 is the same as 3.1.9-1.

The move of using native secure crypto module will be shifted to a new 4.x.x version. As it is a breaking change the impact is too big for a minor release.

3.2.1

The usage of the native crypto module has been fixed. The import and access of the native crypto module has been improved.

3.2.0

In this version Math.random() has been replaced by the random methods of the native crypto module.

For this reason CryptoJS might does not run in some JavaScript environments without native crypto module. Such as IE 10 or before.

If it's absolute required to run CryptoJS in such an environment, stay with 3.1.x version. Encrypting and decrypting stays compatible. But keep in mind 3.1.x versions still use Math.random() which is cryptographically not secure, as it's not random enough.

This version came along with CRITICAL BUG.

DO NOT USE THIS VERSION! Please, go for a newer version!

3.1.x

The 3.1.x are based on the original CryptoJS, wrapped in CommonJS modules.