title: CryptoJS how to generate a key every time?
body: <p>Let assume that I have an Phonegap mobile app, and I want to store some user data(username/pass_hash) in local indexed db for providing login to app in offline.
  I want to encrypt that data of course, and my app already use CryptoJS.
  As I understood, first I need to generate encryption_key by password using PBKDF2, and then just encrypt CryptoJS.AES.
  Example code:</p>
  
  <pre><code>function generateKey(p){
  var salt = CryptoJS.lib.WordArray.random(128/8);
  return CryptoJS.PBKDF2(p, salt, { keySize: 512/32, iterations: 1000 });     
  }
  
  var pass = "test1"; 
  var iv  = CryptoJS.lib.WordArray.random(16);
  key512Bits1000Iterations = generateKey(pass);
  var encrypted = CryptoJS.AES.encrypt("Message", key512Bits1000Iterations, { iv: iv });
  var decrypted = CryptoJS.AES.decrypt(encrypted, key512Bits1000Iterations, { iv: iv });
  
  //decrypting with another key step
  key512Bits1000Iterations2 = generateKey(pass);
  var decrypted2 = CryptoJS.AES.decrypt(encrypted, key512Bits1000Iterations2, { iv: iv });
  console.log("decrypted " + decrypted.toString(CryptoJS.enc.Utf8));
  console.log("decrypted2 " + decrypted2.toString(CryptoJS.enc.Utf8));
  </code></pre>
  
  <p>Dynamic salt and iv are used.
  But when I second time generate key for decryption by same password I'm getting wrong result.(decrypted2 is empty)
  <strong>So I want to ask, what I should store between encryption sessions, 
  salt and iv to ?(but as I understood it should be dynamic )</strong>
  Thanks!</p>