title: How to decrypt encrypted password in localStorage using javaScript
body: <p>I am using localStorage to store data and i want to encrypt the password, then when the password is encrypted in the localStorage i want now to decrypt it to be able to log-in. And i try the encryption is working but the decryption is not working and error message is: 
  <strong>Uncaught SyntaxError: Unexpected end of input</strong>  </p>
  
  <p>I am using CryptoJS v3.1.2 
  code.google.com/p/crypto-js</p>
  
  <p>here the code:</p>
  
  <pre><code>var JsonFormatter = {
  stringify: function (cipherParams) {
  var jsonObj = {ct: cipherParams.ciphertext.toString(CryptoJS.enc.Base64)};
      if (cipherParams.iv) {jsonObj.iv = cipherParams.iv.toString();}
      if (cipherParams.salt) {jsonObj.s = cipherParams.salt.toString();}
      return JSON.stringify(jsonObj);
  },
   parse: function (jsonStr) {
      var jsonObj = JSON.parse(jsonStr);
      var cipherParams = CryptoJS.lib.CipherParams.create({
          ciphertext: CryptoJS.enc.Base64.parse(jsonObj.ct)
      });
      if (jsonObj.iv) {cipherParams.iv = CryptoJS.enc.Hex.parse(jsonObj.iv)}
      if (jsonObj.s) {cipherParams.salt = CryptoJS.enc.Hex.parse(jsonObj.s)}
      return cipherParams;
  }
  };
  </code></pre>
  
  <p>encryption.js</p>
  
  <pre><code>function btnSubmit(){
  
  var p = document.getElementById("setpass").value;
  if(p.length &gt;= 5){
  
      var password = localStorage["Password"];
      var encoded = CryptoJS.AES.encrypt(JSON.stringify(p), password, {format: JsonFormatter}).ciphertext.toString();
      localStorage.setItem("Password", encoded);
  
      jAlert('Password is set', 'URIBlocker');
          window.location.reload();
  }
  else
  {
      //Notification
  } 
  }
  </code></pre>
  
  <p>decrypt.js</p>
  
  <pre><code>function login() {
  
  var usepass = document.getElementById('usepass').value;
  
  var password = localStorage["Password"];
  var encrypted = localStorage.getItem("Password");
  var decrypted = CryptoJS.AES.decrypt(encrypted, password, {formatter: JsonFormatter}).toString();
  var secret = JSON.parse(decrypted);
  
  
  if (usepass === secret)
   {                          
      $('.bd_class').show();
      $('.go_class').hide();
   }
   else
   {
      $('.bd_class').hide();
      $('go_class').show();
  
  }
  }
  </code></pre>
  
  <p>Something is wrong and i don't know the error is Uncaught SyntaxError: Unexpected end of input</p>