What could cause this error: Uncaught TypeError: r.clamp is not a function?

What could cause this error: Uncaught TypeError: r.clamp is not a function?

我正在尝试使用以下函数使用 AES-256-CFB 算法加密 Base64 编码的字符串,当我尝试将结果编码回 Base64 时它会导致以下错误:Uncaught TypeError: r.clamp is not a function

function (base64EncodedString, password) {
    let iv = CryptoJS.lib.WordArray.random(256 / 16);

    let salt = CryptoJS.enc.Hex.parse(iv.toString(CryptoJS.enc.Hex).substr(0, 16));

    let key = CryptoJS.EvpKDF(password, CryptoJS.enc.Hex.parse(salt), { keySize: 256 / 32 });

    let nonEncryptedString = CryptoJS.enc.Base64.parse(base64EncodedString);

    let cipher = CryptoJS.lib.CipherParams.create({ ciphertext: nonEncryptedString , iv: iv, salt: salt, mode: CryptoJS.mode.CFB, padding: CryptoJS.pad.NoPadding,});
    
    let encrypted = CryptoJS.AES.encrypt(cipher, key, {mode: CryptoJS.mode.CFB, padding: CryptoJS.pad.NoPadding, iv: iv});
        
    let ecrytpedBase64 = CryptoJS.enc.Base64.stringify(encrypted);
    
    return ecrytpedBase64;
};

发生这种情况是因为您将加密变量(CipherParams 类型)传递给 stringify 函数,该函数需要一个 WordArray(您的 iv 变量)。

CryptoJS.enc.Base64.stringify(encrypted); // TypeError: r.clamp is not a function
CryptoJS.enc.Base64.stringify(iv); // Ok