tonistiigi / mega

THIS REPO IS NOT MAINTAINED. Unofficial Node.js SDK for Mega
http://tonistiigi.github.com/mega
118 stars 33 forks source link

decode if of the file ? #21

Closed smolleyes closed 10 years ago

smolleyes commented 10 years ago

hi

i search how to get the id of a file, i can get the key with

var node_crypto = require('crypto');

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 }

var file = {"h":"zR8niALR","p":"GJclVaKI","u":"65fYYu5ZLBU","t":0,"a":"p91p4G1aF4DSOUajkxGgTuJDBnGqXIa4XBNSkJu1zwkWjhS8iCZmdoCRWDX3ebmBDemU_VFYvoAGTq8mb6LtuQ","k":"GJclVaKI:vhe23fV90E6We7hrSzoXtZYafjBwjqYSQcAZOlrQGLo","s":2529042,"ts":1395678307};

var k0 = d64("AOUU-DEgRdg4Khd4zM7ndA"); // original folder key var iv = Buffer(16); iv.fill(0);

var k = d64(file.k.split(':')[1]); var u = d64(file.h); // seems to be the id, i have yAlxkCRS when i do right click -> get link on this file in my account var aes = nodecrypto.createDecipheriv('aes-128-ecb', k0, Buffer(0)); aes.setAutoPadding(false); var kfdec = aes.update(k).toString('base64').replace(/+/g,'-').replace(/\//g,'').replace(/=/g,''); var k2dec = from256to128(aes.update(k));

//print decoded key console.log(kfdec)

// how to get the decoded u var ? // goal is the get the same result than get link function in mega

silver659 commented 10 years ago

smolleyes, how to decrypt filename in folder ? you could put an example?