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 static RSAParameters GetParameters(string path, string password) { ContainerHelper.DecontainerizeFile(path, password); RSAParameters key = default; using (var fs = new FileStream(path, FileMode.Open)) { if (new BinaryFormatter().Deserialize(fs) is RSAParameters parameters) { key = parameters; } } ContainerHelper.ContainerizeFile(path, AesHelper.GetNewAesKey(), password); return(key); }