code: function encrypt(data, key) {
      return Promise.resolve().then(function() {
          var bytesLeft = data.byteLength;
          var currentOffset = 0, blockIndex = 0, totalLength = 0;
          var buffers = [];
  
          var next = function() {
              var blockLength = Math.min(BlockSize, bytesLeft);
              bytesLeft -= blockLength;
  
              var blockData = data.slice(currentOffset, currentOffset + blockLength);
              return getBlockHmac(key, blockIndex, blockLength, blockData).then(function(blockHash) {
                  var blockBuffer = new ArrayBuffer(32 + 4);
                  var stm = new BinaryStream(blockBuffer);
                  stm.writeBytes(blockHash);
                  stm.setUint32(blockLength, true);
  
                  buffers.push(blockBuffer);
                  totalLength += blockBuffer.byteLength;
  
                  if (blockData.byteLength > 0) {
                      buffers.push(blockData);
                      totalLength += blockData.byteLength;
                      blockIndex++;
                      currentOffset += blockLength;
                      return next();
                  } else {
                      var ret = new Uint8Array(totalLength);
                      var offset = 0;
                      for (var i = 0; i < buffers.length; i++) {
                          ret.set(new Uint8Array(buffers[i]), offset);
                          offset += buffers[i].byteLength;
                      }
                      return ret.buffer;
                  }
              });
          };
          return next();
      });
  }
docs: Encrypt buffer
  @param {ArrayBuffer} data
  @param {ArrayBuffer} key
  @returns {Promise.<ArrayBuffer>}