title: decrypt using cryptojs not working
body: <p>I m trying to send a encrypted data via json to client and decrypt it in client using cryptojs</p>
  
  <p>My ROR code</p>
  
  <pre><code>def getkey
  
    aes = OpenSSL::Cipher::Cipher.new('AES-128-CBC') 
    aes.encrypt
    key = aes.random_key
  
    session[:key] = key
  
    render :json =&gt; {:mkey =&gt; Base64.encode64(key).gsub(/\n/, '')}
  end
  
  def getdata
      js = "SOME DATA"
  
      aes = OpenSSL::Cipher::Cipher.new('AES-128-CBC')
      aes.encrypt
      aes.key = session[:key]
      encrypted = aes.update(js) + aes.final
  
      encrypted = Base64.encode64(encrypted).gsub(/\n/, '')
  
      render :json =&gt; {:data =&gt; encrypted}
  end
  </code></pre>
  
  <p>My Javascript code</p>
  
  <pre><code>var key = btoa(BASE64_ENCODED_KEY);
  $http({method: 'GET', url: '/appi/getdata/', params: {SOME_PARAMS}})
  .success(function(data, status, headers, config) {
    var dat = btoa(data.data);
    var decrypted = CryptoJS.AES.decrypt(dat, key);
    console.log(decrypted.toString(CryptoJS.enc.Utf8));
  });
  </code></pre>
  
  <p>Getting javascript error "Error: Malformed UTF-8 data." in chrome</p>
  
  <p>Below is a url for simplified jsfiddle for above query</p>
  
  <p><a href="http://jsfiddle.net/7DRdK/1/" rel="nofollow">http://jsfiddle.net/7DRdK/1/</a></p>