我如何在 Native JS 中使用 cryptojs?

How can i use cryptojs in Native JS?

我在 html 中的 NativeJS 中使用 cryptoJs。但是当我用 aesDecrypt(decrypted,key) 解密 txt 时,它不起作用。我已经尝试了许多其他密码,但它仍然不起作用。你们会查看下面的代码并给我一些建议吗?

我在后端尝试了很多密码(如 aes-192-ecb、aes-256-ecb),但仍然不起作用。它报告:错误的加密错误。

Front code: encrypt the txt and send to backend.
function aesEncrypt(data, key) {    
    key = CryptoJS.enc.Utf8.parse(key);    
    let encrypted = CryptoJS.AES.encrypt(data, key, {    
        mode: CryptoJS.mode.ECB,    
        padding: CryptoJS.pad.Pkcs7    
    });    
    return encrypted.toString();    
}   

Backend code: decrypt the txt sent from front.
function aesDecrypt(encrypted, key) {    
    const decipher = crypto.createDecipher('aes192', key);    
    let decrypted = decipher.update(encrypted, 'binary', 'utf8');    
    decrypted += decipher.final('utf8');    
    return decrypted;    
}

看来我在前端和后端都使用了错误的方法。

front code:
<script src="https://cdn.jsdelivr.net/npm/crypto-js@3.1.9-1/crypto-js.js"></script>
let encrypted = CryptoJS.AES.encrypt("txt", "Secret Passphrase").toString();


backend code:
const cryptojs = require("crypto-js");
let txt = cryptojs.AES.decrypt(encrypted , "Secret Passphrase").toString(cryptojs.enc.Utf8);