Ejemplo n.º 1
0
        /// <summary>
        /// Decrypts the file.
        /// </summary>
        /// <param name="file">The file.</param>
        /// <param name="withContent">if set to <c>true</c> [with content].</param>
        /// <returns></returns>
        public DashboardFile DecryptFile(DashboardFile file, bool withContent = false)
        {
            var newFile = new DashboardFile();
            newFile.Content = withContent ? EncryptionHelper.SymmetricDecryptData(file.Content, this.key) : new byte[0];
            newFile.MediaType = EncryptionHelper.SymmetricDecryptInBase64(file.MediaType, this.key);
            newFile.Size = file.Size;

            return newFile;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the encrypted file.
        /// </summary>
        /// <param name="fileName">Name of the file.</param>
        /// <param name="path">The path.</param>
        /// <param name="fileData">The file data.</param>
        /// <param name="mime">The MIME.</param>
        /// <returns></returns>
        public DashboardItem Encrypt(string fileName, string path, byte[] fileData = null, string mime = "")
        {
            path = path ?? string.Empty;
            var item = new DashboardItem();
            if (fileData != null)
            {
                var file = new DashboardFile();
                file.Content = EncryptionHelper.SymmetricEncryptData(fileData, this.key);
                file.Size = fileData.Length;
                file.MediaType = EncryptionHelper.SymmetricEncryptInBase64(mime, key);
                item.File = file;
            }

            item.Name = EncryptionHelper.SymmetricEncryptInBase64(fileName, this.key);
            item.Path = EncryptionHelper.SymmetricEncryptInBase64(path, this.key);
            item.IsFolder = fileData == null;
            return item;
        }