title: Ionic - Store encrypted values in Local Storage
body: <p><strong>Use case</strong>: When online, user launches the Ionic app that prompts for username/password. Credentials are checked against the server and user is allowed to log in. Also, the encrypted password is stored locally (ipad).
  When offline, instead of checking against the server, validate the credentials against the encrypted password stored locally.</p>
  
  <p><strong>What's working</strong>
  Able to use crypto-js library in Ionic to encrypt the password.</p>
  
  <pre><code>var encryptedMessage = CryptoJS.AES.encrypt(password, secretkey);
  </code></pre>
  
  <p><strong>What's not working</strong>
  Now, I am trying the use the angular-local-storage library to save it in local storage.</p>
  
  <pre><code>localStorageService.set('pwdkey', encryptedMessage );
  </code></pre>
  
  <p>It gives me the below error</p>
  
  <pre><code>TypeError: Converting circular structure to JSON
      at Object.stringify (native)
      at toJson (http://localhost:8100/lib/ionic/js/ionic.bundle.js:14637:15)
      at Object.addToLocalStorage (http://localhost:8100/lib/angular-local-storage/dist/angular-local-storage.js:158:19)
      at encryptAndStore (http://localhost:8100/js/controllers.js:550:27)
  </code></pre>
  
  <p>The same code works fine if I pass an unecrypted string instead of the encrypted password. So, it has something to do with the encrypted data.</p>
  
  <p>How can I store encrypted data in local storage? </p>