static StringBuilder GenerateFile(CmdParams cmdParams) { StringBuilder msg = new StringBuilder(); try { if (cmdParams.cmd == "-e") { EncryptFile(cmdParams.inputFile, cmdParams.outputFile); } else if (cmdParams.cmd == "-d") { DecryptFile(cmdParams.inputFile, cmdParams.outputFile); } else // "-t" for test or both { //EncryptFile(cmdParams.inputFile, cmdParams.outputFile); //DecryptFile(cmdParams.inputFile, cmdParams.outputFile); } } catch (Exception ex) { msg.Append(string.Format("{0} {1}", "Unsuccessful.", ex.Message)); return(msg); } msg.AppendLine("Successfully processed the request"); msg.AppendLine(string.Format("{0}{1}", "/in/", cmdParams.inputFile)); msg.AppendLine(string.Format("{0}{1}", "/out/", cmdParams.outputFile)); return(msg); }
static void Main(string[] args) { Console.WriteLine("3DES Encrypt/Decrypt Program."); CmdParams cmdParams = ReadCommandLine(args); StringBuilder result = GenerateFile(cmdParams); Console.WriteLine(result); }
/// <summary> /// Reading command line params /// </summary> /// <param name="args"></param> /// <returns></returns> static CmdParams ReadCommandLine(string[] args) { Console.WriteLine("Argument length: " + args.Length); Console.WriteLine("Supplied Arguments are:"); foreach (Object obj in args) { Console.WriteLine(obj); } CmdParams cmdParams = new CmdParams(); cmdParams.cmd = args[0]; cmdParams.inputFile = args[1]; cmdParams.outputFile = args[2]; return(cmdParams); }
static StringBuilder GenerateFile(CmdParams cmdParams) { StringBuilder msg = new StringBuilder(); try { //Delegate function for either Encrypt or Decrypt method to be called. EncryptionMethod encryptionMethod = null; if (cmdParams.cmd == "-e") { encryptionMethod = EncryptData; } else if (cmdParams.cmd == "-d") { encryptionMethod = DecryptData; } else // "-t" for test or both { //EncryptFile(cmdParams.inputFile, cmdParams.outputFile); //DecryptFile(cmdParams.inputFile, cmdParams.outputFile); } EncryptingFile(cmdParams.inputFile, cmdParams.outputFile, encryptionMethod); } catch (Exception ex) { msg.Append(string.Format("{0} {1}", "Unsuccessful.", ex.Message)); return(msg); } msg.AppendLine("Successfully processed the request"); msg.AppendLine(string.Format("{0}{1}", "/in/", cmdParams.inputFile)); msg.AppendLine(string.Format("{0}{1}", "/out/", cmdParams.outputFile)); return(msg); }