加密标准的JavaScript库。
Cryptojs的积极发展已经停止。该库不再维护。
如今,Nodejs和现代浏览器具有本机Crypto
模块。由于Math.random()
不是加密级安全,因此最新版本的加密js已经将本机加密模块用于随机数生成。加密J的进一步发展将导致它只是本地加密货币的包装。因此,已经停止开发和维护,现在是时候去找本机crypto
模块了。
要求:
npm install crypto-js
ES6导入典型API呼叫签名用例:
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 ) ) ;
模块化包括:
var AES = require ( "crypto-js/aes" ) ;
var SHA256 = require ( "crypto-js/sha256" ) ;
...
console . log ( SHA256 ( "Message" ) ) ;
包括所有库,以获取额外的方法:
var CryptoJS = require ( "crypto-js" ) ;
console . log ( CryptoJS . HmacSHA1 ( "Message" , "Key" ) ) ;
要求:
bower install crypto-js
模块化包括:
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" ) ) ;
} ) ;
包括所有库,以获取额外的方法:
// 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" ) ) ;
} ) ;
< 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 >
请参阅:https://cryptojs.gitbook.io/docs/
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'
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}]
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
使用默认配置更改默认的哈希算法和迭代为PBKDF2预防弱安全性。
自定义KDF HASHER
池塘支撑
修复捆绑释放中的模块订单。
在发布的软件包中包括浏览器字段。
添加了base64编码的URL安全变体。 357
避免使用WebPack添加加密浏览器包。 364
这是一个更新,包括某些环境的破坏更改。
在此版本中, Math.random()
已被本机加密模块的随机方法替换。
因此,Cryptojs可能不会在没有本机加密模块的某些JavaScript环境中运行。例如IE 10或之前或反应天然。
回滚, 3.3.0
与3.1.9-1
相同。
使用本机安全加密模块的举动将转移到新的4.xx
版本。由于这是一个打破的变化,因此影响太大了,对于较小的释放而言。
本机加密模块的使用已固定。本机加密模块的导入和访问已得到改进。
在此版本中, Math.random()
已被本机加密模块的随机方法替换。
因此,Cryptojs可能不会在没有本机加密模块的某些JavaScript环境中运行。例如IE 10或之前。
如果绝对需要在这种环境中运行cryptojs,请使用3.1.x
版本。加密和解密保持兼容。但是请记住3.1.x
版本仍然使用Math.random()
它在密码上不安全,因为它不够随机。
此版本带有CRITICAL
BUG
。
不要使用此版本!请,去寻找一个较新的版本!
3.1.x
基于包裹在commonjs模块中的原始cryptojs。