lib/rmega/nodes/expandable.rb in rmega-0.1.7 vs lib/rmega/nodes/expandable.rb in rmega-0.2.0

- old
+ new

@@ -1,20 +1,24 @@ -require 'rmega/utils' -require 'rmega/nodes/uploadable' -require 'rmega/crypto/crypto' - module Rmega module Nodes module Expandable include Uploadable def create_folder(name) - key = Crypto.random_key - encrypted_attributes = Utils.a32_to_base64 Crypto.encrypt_attributes(key[0..3], {n: name.strip}) - encrypted_key = Utils.a32_to_base64 Crypto.encrypt_key(session.master_key, key) - n = [{h: 'xxxxxxxx', t: 1, a: encrypted_attributes, k: encrypted_key}] - data = session.request a: 'p', t: handle, n: n - Folder.new(session, data['f'][0]) + node_key = NodeKey.random + + # encrypt attributes + attributes_str = "MEGA" + attributes_str << {n: name.strip}.to_json + attributes_str << ("\x00" * (16 - (attributes_str.size % 16))) + encrypted_attributes = aes_cbc_encrypt(node_key.aes_key, attributes_str) + + # Encrypt node key + encrypted_key = aes_ecb_encrypt(session.master_key, node_key.aes_key) + + n = [{h: 'xxxxxxxx', t: 1, a: Utils.base64urlencode(encrypted_attributes), k: Utils.base64urlencode(encrypted_key)}] + data = session.request(a: 'p', t: handle, n: n) + return Folder.new(session, data['f'][0]) end def upload_url(filesize) session.request(a: 'u', s: filesize)['p'] end