コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }