示例#1
0
        /// <summary>
        /// Create a folder on the filesytem
        /// </summary>
        /// <param name="name">Folder name</param>
        /// <param name="parent">Parent node to attach created folder</param>
        /// <exception cref="NotSupportedException">Not logged in</exception>
        /// <exception cref="ApiException">Mega.co.nz service reports an error</exception>
        /// <exception cref="ArgumentNullException">name or parent is null</exception>
        /// <exception cref="ArgumentException">parent is not valid (all types are allowed expect <see cref="NodeType.File" />)</exception>
        public INode CreateFolder(string name, INode parent)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            if (parent == null)
            {
                throw new ArgumentNullException("parent");
            }

            if (parent.Type == NodeType.File)
            {
                throw new ArgumentException("Invalid parent node");
            }

            this.EnsureLoggedIn();

            byte[] key          = Crypto.CreateAesKey();
            byte[] attributes   = Crypto.EncryptAttributes(new Attributes(name), key);
            byte[] encryptedKey = Crypto.EncryptAes(key, this.masterKey);

            CreateNodeRequest request  = CreateNodeRequest.CreateFolderNodeRequest(parent, attributes.ToBase64(), encryptedKey.ToBase64(), key);
            GetNodesResponse  response = this.Request <GetNodesResponse>(request, this.masterKey);

            return(response.Nodes[0]);
        }
        public ShareNodeRequest(INode node, byte[] masterKey, IEnumerable <INode> nodes)
            : base("s2")
        {
            this.Id      = node.Id;
            this.Options = new object[] { new { r = 0, u = "EXP" } };

            INodeCrypto nodeCrypto = (INodeCrypto)node;

            byte[] uncryptedSharedKey = nodeCrypto.SharedKey;
            if (uncryptedSharedKey == null)
            {
                uncryptedSharedKey = Crypto.CreateAesKey();
            }

            this.SharedKey = Crypto.EncryptKey(uncryptedSharedKey, masterKey).ToBase64();

            if (nodeCrypto.SharedKey == null)
            {
                this.Share = new ShareData(node.Id);

                this.Share.AddItem(node.Id, nodeCrypto.FullKey, uncryptedSharedKey);

                // Add all children
                IEnumerable <INode> allChildren = this.GetRecursiveChildren(nodes.ToArray(), node);
                foreach (var child in allChildren)
                {
                    this.Share.AddItem(child.Id, ((INodeCrypto)child).FullKey, uncryptedSharedKey);
                }
            }

            byte[] handle = (node.Id + node.Id).ToBytes();
            this.HandleAuth = Crypto.EncryptKey(handle, masterKey).ToBase64();
        }
示例#3
0
 public MegaAesCtrStreamCrypter(Stream stream)
     : base(stream, stream.Length, Mode.Crypt, Crypto.CreateAesKey(), Crypto.CreateAesKey().CopySubArray(8))
 {
 }