[CryptoJS aes解密抛出“意外令牌U”

问题描述 投票:1回答:2

当我将http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js的内容复制到本地asp.net项目时CryptoJS.AES解密引发异常“意外令牌U”。

以前有人遇到过这个问题吗?引用原始js(http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js)效果很好。

代码很简单:

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script type="text/javascript" src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>
    <script type="text/javascript">
function load() {
    var pb = document.getElementById('pwd');
    var ct = document.getElementById('ct');
    var ce = document.getElementById('ce');
    document.getElementById('bce').onclick = function () {
        try {
            ce.value = CryptoJS.AES.encrypt(ct.value, pb.value);
        } catch (e) {
            alert(e);
        }
    };
    document.getElementById('bcd').onclick = function () {
        try {
            ct.value = CryptoJS.AES.decrypt(ce.value, pb.value);
        } catch (e) {
            alert(e);
        }

    };
}
    </script>
    <style type="text/css">
        .auto-style2 { height: 12px;}
        .auto-style3 {height: 5px;}#ct {height: 246px;width: 542px;}#ce {height: 245px;width: 496px;}#st {height: 160px;width: 538px;}#se {height: 158px;width: 503px;}#pwd {width: 494px;}
    </style>
</head>
<body onload="load();">
    <form id="form1" runat="server">
    <div>
       <input id="pwd" value="pwd" type="text" />
       <table style="height: 456px; width: 853px">
           <tr><td class="auto-style3">Client:</td><td class="auto-style3"></td><td class="auto-style3"></td></tr>
           <tr><td><textarea id="ct"></textarea></td><td><input id="bce" type="button" value="Encrypt"/><br/><input id="bcd" type="button" value="Decrypt"/></td><td><textarea id="ce"></textarea></td></tr>
       </table>
    </div>
    </form>
</body>
</html>
encryption aes cryptojs
2个回答
1
投票

获得解决方案,下载js文件,而不是直接从浏览器复制js内容。


0
投票

下面的几行可能会帮助您解决问题

var decrypt = CryptoJS.AES.decrypt(encryptedQuote , ENCRYPTION_PASSPHRASE);
var originalText = decrypt.toString(CryptoJS.enc.Utf8);
return JSON.parse(originalText);
© www.soinside.com 2019 - 2024. All rights reserved.