using System; using System.IO; using System.Security.Cryptography; using System.Text; namespace Decrypt { /// /// See also: /// https://www.fluxbytes.com/csharp/encrypt-and-decrypt-files-in-c/ /// class Program { static byte[] key = new byte[] { 83, 254, 105, 64, 184, 201, 195, 127, 52, 99, 77, 45, 252, 132, 163, 156 }; static byte[] IV = new byte[] { 189, 23, 137, 56, 204, 241, 242, 118, 28, 89, 9, 198, 224, 111, 186, 125 }; static void Main(string[] args) { if ((args.Length < 1) || !File.Exists(args[0])) { Console.WriteLine("Usage: Decode "); Console.ReadKey(); return; } string fileName = args[0]; string intermediateFile = fileName + ".plain"; /// Intermediate file, output of cryptography decoding string backupFile = fileName + ".bak"; try { using (StreamReader reader = new StreamReader(fileName)) { if (reader.ReadLine().StartsWith(" rotate files if (File.Exists(backupFile)) File.Delete(backupFile); File.Move(fileName, backupFile); File.Move(intermediateFile, fileName); return; } else { Failed(fileName, intermediateFile, ""); return; } } catch (Exception e) { Failed(fileName, intermediateFile, e.Message); return; } } static void Failed(string fileName, string toBeDeleted, string message) { if (File.Exists(toBeDeleted)) { File.Delete(toBeDeleted); } Console.WriteLine(string.Format("Decryption of file {0} failed: {1}", fileName, message)); Console.ReadKey(); } } }