thesadboy / crypto-js

Automatically exported from code.google.com/p/crypto-js
0 stars 0 forks source link

The json format cipher output is not string #53

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. In the given example:
  var encrypted = CryptoJS.AES.encrypt("Message", "Secret Passphrase", { format: JsonFormatter });

    alert(encrypted); // {"ct":"tZ4MsEnfbcDOwqau68aOrQ==","iv":"8a8c8fd8fe33743d3638737ea4a00698","s":"ba06373c8f57179c"}

    var decrypted = CryptoJS.AES.decrypt(encrypted, "Secret Passphrase", { format: JsonFormatter });

    alert(decrypted.toString(CryptoJS.enc.Utf8)); // Message

The returned encrypted is always an object, though stringify function is right.

2. Seems encrypted in CryptoJS.AES.decrypt(encrypted, "Secret Passphrase", { 
format: JsonFormatter }) could be either json string or object, it works and 
get string output.

What is the expected output? What do you see instead?
CryptoJS.AES.encrypt with format option should return the format I want, for 
example json string.

What version of the product are you using? On what operating system?
The script in the given example.

Please provide any additional information below.
I tested the example in latest chrome.

Original issue reported on code.google.com by kiss...@gmail.com on 11 Oct 2012 at 8:56

GoogleCodeExporter commented 8 years ago
It's actually expected behavior that "encrypted" will always be an object. More 
specifically, it will always be a CipherParams object. A CipherParams object 
gives you access to all the parameters used during encryption -- key, IV, salt, 
etc. When you use a CipherParams object in a string context, or if you 
explicitly call toString(), then it's converted to a string using your chosen 
format.

Original comment by Jeff.Mott.OR on 11 Oct 2012 at 9:58

GoogleCodeExporter commented 8 years ago
Thanks for your reply. I have to call toString() to get the json string. It's 
my mistake. The function alert automatically call toString() but I used 
console.log.
So this issue can be dismissed.

Original comment by kiss...@gmail.com on 12 Oct 2012 at 2:21

GoogleCodeExporter commented 8 years ago

Original comment by Jeff.Mott.OR on 12 Oct 2012 at 4:15