简体   繁体   English

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

[英]How to Encrypt in Angularjs and Decrypt in Nodejs using CryptoJS

I need to Encrypt some data in angularjs and Decrypt in nodejs .我需要在nodejsEncrypt一些数据并在angularjsDecrypt I've seen this stackoverflow answer:我看过这个stackoverflow答案:

Angular CryptoJs Encryption Not Decryption in Node JS CryptoJS Angular CryptoJs 在 Node JS 中加密而不是解密 CryptoJS

and tried to use CryptoJS in my angularjs app this way:并尝试以这种方式在我的angularjs应用程序中使用CryptoJS

HTML 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 JS

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

But getting this error:但是得到这个错误:

CryptoJS is not defined

I'm new in angularjs so don't have much idea about how to use different libraries.我是angularjs的新手,所以不太了解如何使用不同的库。 An example of encryption in angularjs and decryption in nodejs would be very helpful.在 angularjs 中encryption和在angularjsdecryptionnodejs将非常有帮助。

You could try to remove the two scripts associated with crypto-js that you already have in the HTML and replace them with:您可以尝试删除 HTML 中已有的与 crypto-js 关联的两个脚本,并将它们替换为:

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

I hope this works.我希望这有效。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM