1

I am getting the following error in my browser (Chrome):

Uncaught TypeError: Object [object global] has no method 'mixIn' aes.js:28
    d.CipherParams.l.extend.init aes.js:28
    c.hasOwnProperty.c.init sha1.js:7
    e jQuery.js:7
    Wc jQuery.js:7
    Wc jQuery.js:7
    n.param jQuery.js:7
    n.extend.ajax jQuery.js:7
    saveCurrentNote (index):88
    selectNote (index):97
    (anonymous function) (index):125
    n.event.dispatch jQuery.js:6
    r.handle

Here is the source code:

<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl ?>/js/jQuery.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl ?>/js/cryptojs/rollups/sha1.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl ?>/js/cryptojs/rollups/aes.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl ?>/js/cryptojs/rollups/pbkdf2.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl ?>/js/cryptojs/rollups/sha3.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl ?>/js/Basic.js"></script>
<script type="text/javascript" src="<?php echo Yii::app()->request->baseUrl ?>/js/Auth.js"></script>

Inside Basic.js:

function encrypt(data, key) {
return CryptoJS.AES.encrypt(data, key);
}

function decrypt(data, key) {
return CryptoJS.AES.decrypt(data, key);
}

And the usage of these functions:

data["name"] = encrypt(data["name"], recall("key"));
data["text"] = encrypt(data["text"], recall("key"));

Here is the link to the CryptoJS library: https://code.google.com/p/crypto-js/

Is there something I am not doing?

1 Answer 1

10

This is an old question but i just ran into same issue. The problem is that the CryptoJS.AES.encrypt method returns an object not a string.

All you need to do is modify your encrypt function as follows:

function encrypt(data, key) {
   return CryptoJS.AES.encrypt(data, key).toString();
}

Likewise, the decrypt function also returns an object so to get the string use:

function decrypt(data, key) {
   return CryptoJS.AES.decrypt(data, key).toString(CryptoJS.enc.Utf8);
}

Not the answer you're looking for? Browse other questions tagged or ask your own question.