document.write与console.log不同?

时间:2013-08-28 03:18:59

标签: javascript

我正在使用这个整洁的库(https://code.google.com/p/crypto-js/#AES)来加密我的消息。

来自以下示例AES示例:

<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/aes.js"></script>

<script>
    var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase");
</script>

当我 document.write(加密) 时,它会返回:

“U2FsdGVkX18W1n0wES5YsBzpRoRB1iu2KqzQiUSe6zE =”

这就是我想要的。但当我 console.log(加密) 时,它会返回:


  

{init:[Function],'$ super':{init:[Function],        toString:[功能],        '$超级':         {extend:[功能],           创建:[功能],           init:[功能],           mixIn:[功能],           clone:[Function]}},ciphertext:{words:         [-463593157,           -130193625,           475395301,           1812962665,           -1322700187,           433662359,           1675036770,           -337777864],        sigBytes:32},key:{init:[Function],        '$超级':         {init:[功能],           toString:[功能],           concat:[功能],           钳:[功能],           克隆:[功能],           随机:[功能],           '$ super':[Object]},        话:         [-1836471768,           609934685,           -835470701,           413762839,           1279413942,           -1961507681,           -1590403020,           392722880,           2059661770,           1403440185,           1364381326,           1252361221],        sigBytes:32},iv:{init:[Function],        '$超级':         {init:[功能],           toString:[功能],           concat:[功能],           钳:[功能],           克隆:[功能],           随机:[功能],           '$ super':[Object]},        字:[2059661770,1403440185,1364381326,1252361221],        sigBytes:16},algorithm:{_ doReset:[Function],        encryptBlock:[功能],        decryptBlock:[功能],        _doCryptBlock:[功能],        keySize:8,        init:[功能],        '$超级':         {cfg:[对象],           重置:[功能],           _doProcessBlock:[功能],           _doFinalize:[功能],           blockSize:4,           init:[功能],           '$ super':[Object]}},mode:{init:[Function],        '$超级':         {createEncryptor:[功能],           createDecryptor:[功能],           init:[功能],           '$ super':[Object]},        加密:         {processBlock:[功能],           init:[功能],           '$ super':[Circular]},        解密:         {processBlock:[功能],           init:[功能],           '$ super':[Circular]}},填充:{pad:[Function],unpad:[Function]},blockSize:4,formatter:{stringify:[Function],   解析:[功能]},盐:{words:[359292117,-310439037],   sigBytes:8}}


为什么两种方法都会返回不同的结果,以及如何使 console.log 的行为类似于 document.write

1 个答案:

答案 0 :(得分:2)

我明白了。事实证明它就像 console.log(encrypted.toString());

一样简单