从github下载了几个文件,在网页测试是成功的。
<html>
<head>
<script src="./core.js" type=“text/javascript”></script>
<script src="./cipher-core.js" type=“text/javascript”></script>
<script src="./aes.js" type=“text/javascript”></script>
<script src="./pad-zeropadding.js" type=“text/javascript”></script>
<script type=“text/javascript”>
var data = “Test String”;
var key = CryptoJS.enc.Latin1.parse(‘1234567812345678’);
var iv = CryptoJS.enc.Latin1.parse(‘1234567812345678’);
//加密
var encrypted = CryptoJS.AES.encrypt(data, key, {
iv: iv,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.ZeroPadding
});
//解密
var decrypted = CryptoJS.AES.decrypt(encrypted, key, {
iv: iv,
padding: CryptoJS.pad.ZeroPadding
});
console.log(decrypted.toString(CryptoJS.enc.Utf8));
</script>
</head>
</html>
但是在小程序的页面js文件里,仅仅是包含文件进来就报错了:
var core = require(’…/…/core’)
var cipher = require(’…/…/cipher-core’)
var config = require(’…/…/config’)
var aes = require(’…/…/aes’)
var pad = require(’…/…/pad-zeropadding’)
出错信息说是CryptoJS未定义,在github里的文档都是以npm安装为基础进行的示例说明,参考不了。