title: How to decrypt an ArrayBuffer?
body: <p>I've been trying to decrypt an ArrayBuffer object using CryptoJS, but so far it always returns a blank WordArray. The files (images) are encrypted in an iOS and Android app, sent to a server, and downloaded in this web app to be decrypted and displayed. The iOS and Android apps are able to decrypt the files without problems, so there's nothing wrong with the encryption process. </p>
  
  <p>The files are downloaded with an <code>XMLHttpRequest</code> with <code>responseType</code> set to <code>arraybuffer</code>. Here's my code so far:</p>
  
  <pre><code>// Decrypt a Base64 encrypted string (this works perfectly)
  String.prototype.aesDecrypt = function(key) {
  
      var nkey = CryptoJS.enc.Hex.parse(key.sha256());
      return CryptoJS.AES.decrypt(this.toString(), nkey, {
          iv: CryptoJS.enc.Hex.parse('00000000000000000000000000000000'),
          mode: CryptoJS.mode.CBC,
          padding: CryptoJS.pad.Pkcs7
      }).toString(CryptoJS.enc.Utf8);
  
  }
  
  // Decrypt a plain encrypted ArrayBuffer (this is the problem, it always outputs an empty WordArray)
  ArrayBuffer.prototype.aesDecrypt = function(key) {
  
      // Get key
      if (!key) return null;
      var nkey = CryptoJS.enc.Hex.parse(key.sha256());
  
      // Get input (if I pass the ArrayBuffer directly to the create function, it returns
      // a WordList with sigBytes set to NaN)
      //var input = CryptoJS.lib.WordArray.create(this);
      var input = CryptoJS.lib.WordArray.create(new Uint8Array(this));
  
      // Decrypt
      var output = CryptoJS.AES.decrypt(input, nkey, {
          iv: CryptoJS.enc.Hex.parse('00000000000000000000000000000000'),
          mode: CryptoJS.mode.CBC,
          padding: CryptoJS.pad.Pkcs7
      });
  
      // Output is an empty WordList
      console.log("Output: ", output);
  
  }
  </code></pre>
  
  <p>Another question I have is how do you convert a <code>WordArray</code> to an <code>ArrayBuffer</code>?</p>