/// <summary> /// /// </summary> public static void ShredFile(string path, CipherType cipherType, bool nameObfuscation = true, bool propertyObfuscation = true) { if ((File.GetAttributes(path) & FileAttributes.Directory) == FileAttributes.Directory) { throw new FileNotFoundException(path); } if (!File.Exists(path)) { throw new FileNotFoundException(path); } switch (cipherType) { case CipherType.Otp: OtpHelper.EncryptWithoutKey(path); break; case CipherType.Aes: AesHelper.EncryptFile(AesHelper.GetNewAesKey(), path); break; } if (propertyObfuscation) { ObfuscateFileProperties(path); } if (nameObfuscation) { path = ObfuscateFileName(path); } File.Delete(path); }
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); } }); }