get name files of a mega.nz folder in nodejs
<p>Request to api of mega.nz, parse url for get private key of folder, and try decode name of files from responde of request, by crypto of nodejs.</p>

<p>My code:</p>

<pre><code>const crypto = require('crypto')
const parse = require('url').parse
const request = require('request')

const link = 'https://mega.nz/#F!gE5WkDpS!Yh6AQtYHPgi-rEkir_gAEw'
const api = 'https://eu.api.mega.co.nz/cs?id=-1771463320&amp;n=MBwjmCqR'

function d64 (s) {
  s += '=='.substr((2 - s.length * 3) &amp; 3)
  s = s.replace(/-/g, '+').replace(/_/g, '/').replace(/,/g, '')
  return new Buffer(s, 'base64')
}

function from256to128 (s) {
  var o = new Buffer(16)
  for (var i = 0; i &lt; 16; i++) {
    o[i] = s[i] ^ s[i + 16]
  }
  return o
}

function decodeName (at) {
  var end = at.length
  while (!at.readUInt8(end - 1)) end--
  return at.slice(0, end).toString()
}

const url = parse(link)
const split = url.hash.split('!')
const k0 = d64(split[2])

request({
  method: 'POST', uri: api, body: '[{"a":"f","c":1,"r":1,"ca":1}]'
}, (e, r, b) =&gt; {
  if (!e &amp;&amp; r.statusCode === 200) {
    for (let file of JSON.parse(b)[0].f) {
      if (file.t === 1) {
        let k = d64(file.k.split(':')[1])
        let a = d64(file.a)
        let aes = crypto.createDecipheriv('aes-128-ecb', k0, Buffer(0))
        aes.setAutoPadding(false)
        let kdec = aes.update(k)
        aes = crypto.createDecipheriv('aes-128-cbc', kdec, Buffer(16))
        aes.setAutoPadding(false)
        let name = decodeName(aes.update(a))
        console.log(name)
      } else {
        let k = d64(file.k.split(':')[1])
        let a = d64(file.a)
        let aes = crypto.createDecipheriv('aes-128-ecb', k0, Buffer(0))
        aes.setAutoPadding(false)
        let k2dec = from256to128(aes.update(k))
        aes = crypto.createDecipheriv('aes-128-cbc', k2dec, Buffer(16))
        aes.setAutoPadding(false)
        let name = decodeName(aes.update(a))
        console.log(name)
      }
    }
  }
})
</code></pre>

<p>My output is more broken text, i try change url and get more broken text:</p>

<pre><code>�MzM�ݾ��+,�BW���p�K����
</code></pre>