javascript - get name files of a mega.nz folder in nodejs - Stack Overflow

Request to api of mega.nz, parse url for get private key of folder, and try decode name of files from r

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.

My code:

const crypto = require('crypto')
const parse = require('url').parse
const request = require('request')

const link = '!gE5WkDpS!Yh6AQtYHPgi-rEkir_gAEw'
const api = ';n=MBwjmCqR'

function d64 (s) {
  s += '=='.substr((2 - s.length * 3) & 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 < 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) => {
  if (!e && 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)
      }
    }
  }
})

My output is more broken text, i try change url and get more broken text:

�MzM�ݾ��+,�BW���p�K����

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.

My 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&n=MBwjmCqR'

function d64 (s) {
  s += '=='.substr((2 - s.length * 3) & 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 < 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) => {
  if (!e && 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)
      }
    }
  }
})

My output is more broken text, i try change url and get more broken text:

�MzM�ݾ��+,�BW���p�K����
Share Improve this question asked Jul 8, 2016 at 20:59 lobitolobito 1211 gold badge1 silver badge5 bronze badges 2
  • You're requesting info for the MBwjmCqR folder and trying to decrypt it using gE5WkDpS key. But seems it's not the only problem. – Gustavo Rodrigues Commented Jul 26, 2016 at 17:52
  • Found the problem: use the correct key (as I noted above) then use Buffer.alloc(0) and Buffer.alloc(16) instead of Buffer(0) and Buffer(16). – Gustavo Rodrigues Commented Dec 6, 2016 at 11:00
Add a ment  | 

1 Answer 1

Reset to default 1

There are two errors in your code:

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

You're requesting MBwjmCqR folder info but using gE5WkDpS key.

let aes = crypto.createDecipheriv('aes-128-ecb', k0, Buffer(0))
aes = crypto.createDecipheriv('aes-128-cbc', kdec, Buffer(16))

Using Buffer(size) will not initialize it, so the Buffer will contain data that was previously in memory. Use Buffer.alloc(size, 0) to initialize it with zeroes, which will match MEGA's implementation.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745420552a4626945.html

相关推荐

  • javascript - get name files of a mega.nz folder in nodejs - Stack Overflow

    Request to api of mega.nz, parse url for get private key of folder, and try decode name of files from r

    5小时前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信