// (c) 2006 Richard Grimes // www.grimes.demon.co.uk using System; using System.IO; using System.Security.Cryptography; class App { // Parameters: e|d infile outfile static void Main(string[] args) { if (args.Length < 3) { Console.WriteLine("Usage: protect e|d infile outfile"); return; } bool bEncrypt = (args[0][0] == 'e'); if (!File.Exists(args[1])) { Console.WriteLine("{0} does not exist", args[1]); return; } if (File.Exists(args[2])) { File.Delete(args[2]); } byte[] inData, outData; using (FileStream fsIn = File.OpenRead(args[1])) { inData = new byte[fsIn.Length]; fsIn.Read(inData, 0, inData.Length); } if (bEncrypt) outData = ProtectedData.Protect(inData, null, DataProtectionScope.CurrentUser); else outData = ProtectedData.Unprotect(inData, null, DataProtectionScope.CurrentUser); using (FileStream fsOut = File.OpenWrite(args[2])) { fsOut.Write(outData, 0, outData.Length); } } }