Ejemplo n.º 1
0
        /// <summary>
        /// Retrieve public properties of a file from a specified Uri
        /// </summary>
        /// <param name="uri">Uri to retrive properties</param>
        /// <exception cref="NotSupportedException">Not logged in</exception>
        /// <exception cref="ApiException">Mega.co.nz service reports an error</exception>
        /// <exception cref="ArgumentNullException">uri is null</exception>
        /// <exception cref="ArgumentException">Uri is not valid (id and key are required)</exception>
        public INodePublic GetNodeFromLink(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            this.EnsureLoggedIn();

            string id;

            byte[] iv, metaMac, fileKey;
            this.GetPartsFromUri(uri, out id, out iv, out metaMac, out fileKey);

            // Retrieve attributes
            DownloadUrlRequestFromId downloadRequest  = new DownloadUrlRequestFromId(id);
            DownloadUrlResponse      downloadResponse = this.Request <DownloadUrlResponse>(downloadRequest);

            return(new NodePublic(downloadResponse, fileKey));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Retrieve a Stream to download and decrypt the specified Uri
        /// </summary>
        /// <param name="uri">Uri to download</param>
        /// <exception cref="NotSupportedException">Not logged in</exception>
        /// <exception cref="ApiException">Mega.co.nz service reports an error</exception>
        /// <exception cref="ArgumentNullException">uri is null</exception>
        /// <exception cref="ArgumentException">Uri is not valid (id and key are required)</exception>
        /// <exception cref="DownloadException">Checksum is invalid. Downloaded data are corrupted</exception>
        public Stream Download(Uri uri)
        {
            if (uri == null)
            {
                throw new ArgumentNullException("uri");
            }

            this.EnsureLoggedIn();

            string id;

            byte[] iv, metaMac, fileKey;
            this.GetPartsFromUri(uri, out id, out iv, out metaMac, out fileKey);

            // Retrieve download URL
            DownloadUrlRequestFromId downloadRequest  = new DownloadUrlRequestFromId(id);
            DownloadUrlResponse      downloadResponse = this.Request <DownloadUrlResponse>(downloadRequest);

            Stream dataStream = this.webClient.GetRequestRaw(new Uri(downloadResponse.Url));

            return(new MegaAesCtrStreamDecrypter(dataStream, downloadResponse.Size, fileKey, iv, metaMac));
        }