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
Including all libraries, for access to extra methods:
// Above-mentioned will work or use this simple formrequire.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>
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 CRITICALBUG.
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.