简体   繁体   中英

document.write different from console.log?

I'm using this neat library ( https://code.google.com/p/crypto-js/#AES ) to encrypt my messages.

From the following example AES example:

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

When I document.write(encrypted) it returns:

"U2FsdGVkX18W1n0wES5YsBzpRoRB1iu2KqzQiUSe6zE="

Which is what I want. But when I console.log(encrypted) it returns:


{ init: [Function], '$super': { init: [Function], toString: [Function], '$super': { extend: [Function], create: [Function], init: [Function], mixIn: [Function], clone: [Function] } }, ciphertext: { words: [ -463593157, -130193625, 475395301, 1812962665, -1322700187, 433662359, 1675036770, -337777864 ], sigBytes: 32 }, key: { init: [Function], '$super': { init: [Function], toString: [Function], concat: [Function], clamp: [Function], clone: [Function], random: [Function], '$super': [Object] }, words: [ -1836471768, 609934685, -835470701, 413762839, 1279413942, -1961507681, -1590403020, 392722880, 2059661770, 1403440185, 1364381326, 1252361221 ], sigBytes: 32 }, iv: { init: [Function], '$super': { init: [Function], toString: [Function], concat: [Function], clamp: [Function], clone: [Function], random: [Function], '$super': [Object] }, words: [ 2059661770, 1403440185, 1364381326, 1252361221 ], sigBytes: 16 }, algorithm: { _doReset: [Function], encryptBlock: [Function], decryptBlock: [Funct ion], _doCryptBlock: [Function], keySize: 8, init: [Function], '$super': { cfg: [Object], reset: [Function], _doProcessBlock: [Function], _doFinalize: [Function], blockSize: 4, init: [Function], '$super': [Object] } }, mode: { init: [Function], '$super': { createEncryptor: [Function], createDecryptor: [Function], init: [Function], '$super': [Object] }, Encryptor: { processBlock: [Function], init: [Function], '$super': [Circular] }, Decryptor: { processBlock: [Function], init: [Function], '$super': [Circular] } }, padding: { pad: [Function], unpad: [Function] }, blockSize: 4, formatter: { stringify: [Function], parse: [Function] }, salt: { words: [ 359292117, -310439037 ], sigBytes: 8 } }


Why do both methods return different results and how to I make console.log behave like document.write ?

I figured it out. Turns out it's as simple as console.log(encrypted.toString());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM