CryptoJS不能只使用AES而不会出错

时间:2017-10-20 19:20:04

标签: javascript

我有一个gulpfile连接我的依赖项,生成一个文件。

最终输出文件中包含CryptoJS。如果我使用整个库:
node_modules/crypto-js/crypto-js.js

我可以加密数据:

async function save(data) {
    let saveData = CryptoJS.AES.encrypt(data, 'My Secret').toString();
}

如果我只使用我需要的部分库AES,我会收到以下错误:

  

未捕获(承诺)TypeError:无法读取未定义

的属性'create'

我正在连接的文件按此顺序排列:

let fileList = [
  'node_modules/crypto-js/core.js',
  'node_modules/crypto-js/cipher-core.js',
  'node_modules/crypto-js/enc-utf8.js',
  'node_modules/crypto-js/aes.js',
]

我错过了一个文件吗?

修改

错误堆栈:

Uncaught (in promise) TypeError: Cannot read property 'create' of undefined
    at Object.execute (gamesmart.js:2067)
    at Object.encrypt (gamesmart.js:2114)
    at Object.encrypt (gamesmart.js:1493)
    at Object.<anonymous> (gamesmart.js:42)
    at Generator.next (<anonymous>)
    at gamesmart.js:7
    at new Promise (<anonymous>)
    at __awaiter (gamesmart.js:3)
    at Object.save (gamesmart.js:41)
    at HTMLDocument.document.addEventListener (ajax.js:3)
execute @   gamesmart.js:2067
encrypt @   gamesmart.js:2114
encrypt @   gamesmart.js:1493
(anonymous) @   gamesmart.js:42
(anonymous) @   gamesmart.js:7
__awaiter   @   gamesmart.js:3
save    @   gamesmart.js:41
document.addEventListener   @   ajax.js:3
async function (async)      
document.addEventListener

这是在这个功能中(来自核心而不是我的)(var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt)):

execute: function (password, keySize, ivSize, salt) {
            // Generate random salt
            if (!salt) {
                salt = WordArray.random(64/8);
            }

            // Derive key and IV
            var key = EvpKDF.create({ keySize: keySize + ivSize }).compute(password, salt);

            // Separate key and IV
            var iv = WordArray.create(key.words.slice(keySize), ivSize * 4);
            key.sigBytes = keySize * 4;

            // Return params
            return CipherParams.create({ key: key, iv: iv, salt: salt });
        }

0 个答案:

没有答案