本文介绍了CryptoJS没有方法mixIn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的浏览器(Chrome)出现以下错误:

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

这是源代码:

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

内部Basic.js:

Inside Basic.js:

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

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

以及这些功能的用法:

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

以下是CryptoJS库的链接: https://code.google.com/p/crypto-js/

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

我有什么不做的吗?

推荐答案

这是一个老问题,但我遇到了同样的问题.问题在于CryptoJS.AES.encrypt方法返回的对象不是字符串.

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();
}

同样,decrypt函数也返回一个对象,以便使用该字符串:

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);
}

这篇关于CryptoJS没有方法mixIn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-07 14:25