【问题标题】:CryptoJS aes decrypt throws "Unexpected token U"CryptoJS aes 解密抛出“意外的令牌 U”
【发布时间】:2020-04-30 16:35:42
【问题描述】:

当我将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


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

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

      var decrypt = CryptoJS.AES.decrypt(encryptedQuote , ENCRYPTION_PASSPHRASE);
      var originalText = decrypt.toString(CryptoJS.enc.Utf8);
      return JSON.parse(originalText);
      

      【讨论】:

        猜你喜欢
        • 2021-05-29
        • 1970-01-01
        • 2019-08-13
        • 1970-01-01
        • 2016-12-12
        • 1970-01-01
        • 2015-06-09
        • 1970-01-01
        • 2014-06-06
        相关资源
        最近更新 更多