public ContainerizeFileTask(string filePath, ContainerizationSettingsModel settingsModel) : base(ResourceType.File, filePath) { InnerTask = new Task(() => { if (Path.GetExtension(filePath).Equals(settingsModel.Extension)) { return; } ContainerHelper.ContainerizeFile(filePath, AesHelper.GetNewAesKey(), settingsModel.Password); var newPath = FileGeneratorHelper.GetValidFileNameForDirectory( DirectoryHelper.GetDirectoryPath(filePath), Path.GetFileNameWithoutExtension(filePath), settingsModel.Extension); File.Move(filePath, newPath); Result.Value = new FileModel { File = Path.GetFileName(filePath), Time = DateTime.Now, Secured = newPath }; }); }
public static void DecontainerizeDirectoryFiles(FolderModel masterModel, string folderPath, ContainerizationSettingsModel settingsModel, bool includeSubFolders) { foreach (var filePath in Directory.GetFiles(folderPath).Where(x => Path.GetExtension(x).Equals(settingsModel.Extension))) { ContainerHelper.DecontainerizeFile(filePath, settingsModel.Password); var fileModel = folderPath.Equals(masterModel.Uri) ? masterModel.FileModels.FirstOrDefault(x => x.Secured.Equals(filePath)) : GetFileModel(masterModel, file => file.Secured.Equals(filePath)); var newPath = FileGeneratorHelper.GetValidFileNameForDirectory( GetDirectoryPath(filePath), Path.GetFileNameWithoutExtension(filePath), fileModel != null ? Path.GetExtension(fileModel.File) : string.Empty); File.Move(filePath, newPath); } if (!includeSubFolders) { return; } foreach (var subFolderPath in Directory.GetDirectories(folderPath)) { DecontainerizeDirectoryFiles(masterModel, subFolderPath, settingsModel, true); } }
public DecontainerizeOtherFileTask(string path, string password) : base(ResourceType.File, path) { InnerTask = new Task(() => { ContainerHelper.DecontainerizeFile(path, password); var newFilePath = FileGeneratorHelper.GetValidFileNameForDirectory( DirectoryHelper.GetDirectoryPath(path), Path.GetFileNameWithoutExtension(path), string.Empty); File.Move(path, newFilePath); }); }
public OtpTransformTask(string filePath, string ext, string keyFilePath = "", bool encrypt = true) : base(ResourceType.File, filePath, keyFilePath) { InnerTask = new Task(() => { string newFileName; if (encrypt) { newFileName = FileGeneratorHelper.GetValidFileNameForDirectory( DirectoryHelper.GetDirectoryPath(filePath), Path.GetFileName(filePath), ext); } else { if (!filePath.EndsWith(ext, StringComparison.Ordinal)) { throw new InvalidEncryptedFileException(); } var name = filePath.RemoveLast(ext.Length); newFileName = FileGeneratorHelper.GetValidFileNameForDirectory( DirectoryHelper.GetDirectoryPath(name), Path.GetFileName(name), string.Empty); } if (newFileName == null) { throw new NoSuitableNameFoundException(); } File.Move(filePath, newFileName); if (string.IsNullOrEmpty(keyFilePath)) { OtpHelper.EncryptWithoutKey(newFileName); } else { OtpHelper.Transform(newFileName, keyFilePath); } }); }
public DecontainerizeFileTask(string filePath, string password, bool removeAfter = false, bool openAfter = false) : base(ResourceType.File, filePath) { InnerTask = new Task(() => { ContainerHelper.DecontainerizeFile(filePath, password); var path = FileGeneratorHelper.GetValidFileNameForDirectory( DirectoryHelper.GetDirectoryPath(filePath), Path.GetFileNameWithoutExtension(filePath), string.Empty); File.Move(filePath, path); Result.Value = new DecontainerizeFileTaskResultModel { Model = path.ToFileModel(), NewPath = path, DeleteAfter = removeAfter, OpenAfter = openAfter }; }); }
public DecontainerizeFileTask(FileModel model, string password, bool removeAfter = false, bool openAfter = false) : base(ResourceType.File, model.Secured) { InnerTask = new Task(() => { ContainerHelper.DecontainerizeFile(model.Secured, password); var path = FileGeneratorHelper.GetValidFileNameForDirectory( DirectoryHelper.GetDirectoryPath(model.Secured), Path.GetFileNameWithoutExtension(model.File), Path.GetExtension(model.File)); File.Move(model.Secured, path); Result.Value = new DecontainerizeFileTaskResultModel { Model = model, NewPath = path, DeleteAfter = removeAfter, OpenAfter = openAfter }; }); }
public BulkExportKeysTask(string folderPath, string sessionPassword, IEnumerable <FileModel> models, RSAParameters privateKey, string extension) : base(ResourceType.Folder, folderPath) { InnerTask = new Task(() => { var key = string.Empty; var keysNotCreated = new List <string>(); var keyCreated = false; foreach (var model in models) { if (ContainerHelper.ValidateContainer(model.Secured, sessionPassword)) { if (keyCreated) { continue; } var keyPath = FileGeneratorHelper.GetValidFileNameForDirectory( folderPath, Path.GetFileNameWithoutExtension(Path.GetRandomFileName()), extension); RsaKeyWriterHelper.SerializeTextToFile(privateKey, sessionPassword, keyPath); key = keyPath; keyCreated = true; } else { keysNotCreated.Add(model.Secured); } } Result.Value = new BulkExportKeysTaskResultModel { KeyPath = key, NotCreated = keysNotCreated }; }); }
public static IEnumerable <FileModel> EnumerateAndSecureFiles(string folderPath, ContainerizationSettingsModel settingsModel) { var fileModels = new List <FileModel>(); foreach (var filePath in Directory.GetFiles(folderPath).Where(x => !Path.GetExtension(x).Equals(settingsModel.Extension))) { ContainerHelper.ContainerizeFile(filePath, AesHelper.GetNewAesKey(), settingsModel.Password); var newPath = FileGeneratorHelper.GetValidFileNameForDirectory( GetDirectoryPath(filePath), Path.GetFileNameWithoutExtension(filePath), settingsModel.Extension); File.Move(filePath, newPath); fileModels.Add(new FileModel { File = Path.GetFileName(filePath), Time = DateTime.Now, Secured = newPath }); } return(fileModels); }