code: function layerEncrypt(data, count, key) {
    var result = bufferShim.alloc(0);
    var total = data.length;
    for (var offset = 0; offset < total; ) {
      var length = Math.min(total - offset, 0x400);
      var leLength = bufferShim.alloc(2);
      leLength.writeUInt16LE(length,0);
  
      var nonce = bufferShim.alloc(8);
      writeUInt64LE(count.value++, nonce, 0);
  
      var result_Buffer = bufferShim.alloc(length);
      var result_mac = bufferShim.alloc(16);
      encryptAndSeal(key, nonce, data.slice(offset, offset + length),
        leLength,result_Buffer, result_mac);
  
      offset += length;
  
      result = Buffer.concat([result,leLength,result_Buffer,result_mac]);
    }
    return result;
  }
docs: Security Layer Enc/Dec