Mark Yuan
Mark Yuan

Reputation: 860

CryptoJS aes decrypt throws "Unexpected token U"

When I copied the content of http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js to local asp.net project CryptoJS.AES decrypt throws exception "Unexpected token U".

Does any one met this issue before? Reference the original js (http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js) works fine.

The code was simple:

<!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>

Upvotes: 1

Views: 1099

Answers (2)

Sandeep M
Sandeep M

Reputation: 248

Below lines might help you to resolve issue

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

Upvotes: 0

Mark Yuan
Mark Yuan

Reputation: 860

Got the solution, download the js file instead of copying the js content from browser directly.

Upvotes: 1

Related Questions