如何使用CryptoJS在Angularjs中加密和在Nodejs中解密

问题描述

我需要Encrypt中的angularjsDecrypt中的nodejs的一些数据。我已经看到了这个stackoverflow答案:

Angular CryptoJs Encryption Not Decryption in Node JS CryptoJS

并尝试通过以下方式在我的CryptoJS应用中使用angularjs

HTML

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/components/enc-base64-min.js"></script>

JS

app.controller('test',function ($scope) {
   var param = 'abc'
   var encry = CryptoJS.AES.encrypt(param,'key');
   console.log(encry);
});

但是出现此错误

CryptoJS is not defined

我是angularjs的新手,所以对如何使用不同的库没有太多的了解。 encryption中的angularjsdecryption中的nodejs的示例将非常有帮助。

解决方法

您可以尝试删除HTML中已经具有的与crypto-js关联的两个脚本,并将其替换为:

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.0.0/crypto-js.min.js"></script>

我希望这行得通。