JavaScript library of crypto standards.
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.
Requirements:
- Node.js
- npm (Node.js package manager)
npm install crypto-jsES6 import for typical API call signing use case:
importsha256from'crypto-js/sha256';importhmacSHA512from'crypto-js/hmac-sha512';importBase64from'crypto-js/enc-base64';constmessage,nonce,path,privateKey;// ...consthashDigest=sha256(nonce+message);consthmacDigest=Base64.stringify(hmacSHA512(path+hashDigest,privateKey));Modular include:
varAES=require("crypto-js/aes");varSHA256=require("crypto-js/sha256"); ... console.log(SHA256("Message"));Including all libraries, for access to extra methods:
varCryptoJS=require("crypto-js");console.log(CryptoJS.HmacSHA1("Message","Key"));Requirements:
- Node.js
- Bower (package manager for frontend)
bower install crypto-jsModular 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 formrequire.config({paths: {'crypto-js': 'path-to/bower_components/crypto-js/crypto-js'}});require(["crypto-js"],function(CryptoJS){console.log(CryptoJS.HmacSHA1("Message","Key"));});<scripttype="text/javascript" src="path-to/bower_components/crypto-js/crypto-js.js"></script><scripttype="text/javascript">varencrypted=CryptoJS.AES(...);varencrypted=CryptoJS.SHA256(...);</script>See: https://cryptojs.gitbook.io/docs/
varCryptoJS=require("crypto-js");// Encryptvarciphertext=CryptoJS.AES.encrypt('my message','secret key 123').toString();// Decryptvarbytes=CryptoJS.AES.decrypt(ciphertext,'secret key 123');varoriginalText=bytes.toString(CryptoJS.enc.Utf8);console.log(originalText);// 'my message'varCryptoJS=require("crypto-js");vardata=[{id: 1},{id: 2}]// Encryptvarciphertext=CryptoJS.AES.encrypt(JSON.stringify(data),'secret key 123').toString();// Decryptvarbytes=CryptoJS.AES.decrypt(ciphertext,'secret key 123');vardecryptedData=JSON.parse(bytes.toString(CryptoJS.enc.Utf8));console.log(decryptedData);// [{id: 1},{id: 2}]crypto-js/corecrypto-js/x64-corecrypto-js/lib-typedarrays
crypto-js/md5crypto-js/sha1crypto-js/sha256crypto-js/sha224crypto-js/sha512crypto-js/sha384crypto-js/sha3crypto-js/ripemd160
crypto-js/hmac-md5crypto-js/hmac-sha1crypto-js/hmac-sha256crypto-js/hmac-sha224crypto-js/hmac-sha512crypto-js/hmac-sha384crypto-js/hmac-sha3crypto-js/hmac-ripemd160
crypto-js/pbkdf2
crypto-js/aescrypto-js/tripledescrypto-js/rc4crypto-js/rabbitcrypto-js/rabbit-legacycrypto-js/evpkdf
crypto-js/format-opensslcrypto-js/format-hex
crypto-js/enc-latin1crypto-js/enc-utf8crypto-js/enc-hexcrypto-js/enc-utf16crypto-js/enc-base64
crypto-js/mode-cfbcrypto-js/mode-ctrcrypto-js/mode-ctr-gladmancrypto-js/mode-ofbcrypto-js/mode-ecb
crypto-js/pad-pkcs7crypto-js/pad-ansix923crypto-js/pad-iso10126crypto-js/pad-iso97971crypto-js/pad-zeropaddingcrypto-js/pad-nopadding
Change default hash algorithm and iteration's for PBKDF2 to prevent weak security by using the default configuration.
Custom KDF Hasher
Blowfish support
Fix module order in bundled release.
Include the browser field in the released package.json.
Added url safe variant of base64 encoding. 357
Avoid webpack to add crypto-browser package. 364
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.
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.
The usage of the native crypto module has been fixed. The import and access of the native crypto module has been improved.
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!
The 3.1.x are based on the original CryptoJS, wrapped in CommonJS modules.