Esempio n. 1
0
        public static void StartQuik()
        {
            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();

            fileMap.ExeConfigFilename = configFile;
            Configuration config =
                ConfigurationManager.OpenMappedExeConfiguration(fileMap,
                                                                ConfigurationUserLevel.None);

            qconf = (QuikConfiguration)config.GetSection("QuikConfiguration");

            if (qconf == null)
            {
                Main(new string[] { "-setup" });
                return;
            }

            Console.WriteLine(@"Starting '" + qconf.QuikPath + "'.");


            // From MSDN: Key containers provide the most secure way to persist cryptographic keys
            // and keep them secret from malicious third parties.
            string containerName = qconf.Name.GetStringHash();
            string salt          = MachineIdentificator.GetUniqueStringID();
            var    RSAProvider   = RsaUtilities.GetRSAProviderFromContainer(containerName + salt, false);


            //Decrupt sensitive parts

            qconf.User     = Encoding.UTF8.GetString(RSAProvider.Decrypt(Convert.FromBase64String(qconf.User), false));
            qconf.Password = Encoding.UTF8.GetString(RSAProvider.Decrypt(Convert.FromBase64String(qconf.Password), false));



            StartProcessAndSendKeys();

            //Console.WriteLine(qconf.Name);
            //Console.WriteLine(qconf.QuikPath);
            //Console.WriteLine(qconf.User);
            //Console.WriteLine(qconf.Password);
        }
Esempio n. 2
0
        public static void Setup()
        {
            // Get the application configuration file.
            Configuration config =
                ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (File.Exists(configFile))
            {
                File.Delete(configFile);
            }

            do
            {
                qconf.Name     = "";
                qconf.QuikPath = "";
                qconf.User     = "";
                qconf.Password = "";

                while (string.IsNullOrEmpty(qconf.Name))
                {
                    Console.WriteLine(@"Please enter connection name, e.g. MyQuik (max 50 symbols)");
                    qconf.Name = Console.ReadLine().Trim(new char[] { '"', ' ', "'".ToCharArray()[0] });
                    if (qconf.Name.Length > 50)
                    {
                        Console.WriteLine(@"Too long");
                        qconf.Name = "";
                    }
                }
                ;

                while (string.IsNullOrEmpty(qconf.QuikPath))
                {
                    Console.WriteLine(@"Please enter the full path to Quik, e.g. C:\Quik\info.exe");
                    qconf.QuikPath = Console.ReadLine().Trim(new char[] { '"', ' ', "'".ToCharArray()[0] });
                }

                while (string.IsNullOrEmpty(qconf.User))
                {
                    Console.WriteLine(@"Please enter user name, e.g. Smith John or Иванов Иван (max 50 symbols)");
                    qconf.User = Console.ReadLine().Trim(new char[] { '"', ' ', "'".ToCharArray()[0] });
                    if (qconf.User.Length > 50)
                    {
                        Console.WriteLine(@"Too long");
                        qconf.User = "";
                    }
                }

                while (string.IsNullOrEmpty(qconf.Password))
                {
                    Console.WriteLine(@"Please enter password (it will be visible on the screen), e.g. myPa$$w0rD (max 50 symbols)");
                    qconf.Password = Console.ReadLine().Trim();
                    if (qconf.Password.Length > 50)
                    {
                        Console.WriteLine(@"Too long");
                        qconf.Password = "";
                    }
                }

                Console.WriteLine(@"Is everything correct (Y/N)?");
            } while (Console.ReadLine().ToLower().Substring(0, 1) != "y");

            //Console.Clear();



            // From MSDN: Key containers provide the most secure way to persist cryptographic keys
            // and keep them secret from malicious third parties.
            string containerName = qconf.Name.GetStringHash();
            string salt          = MachineIdentificator.GetUniqueStringID();
            var    RSAProvider   = RsaUtilities.GetRSAProviderFromContainer(containerName + salt, false);

            //Encrypt sensitive parts
            qconf.User = Convert.ToBase64String(
                RSAProvider.Encrypt(Encoding.UTF8.GetBytes(qconf.User), false)
                );
            qconf.Password = Convert.ToBase64String(
                RSAProvider.Encrypt(Encoding.UTF8.GetBytes(qconf.Password), false)
                );

            // You need to remove the old settings object before you can replace it
            config.Sections.Remove("QuikConfiguration");
            // with an updated one
            config.Sections.Add("QuikConfiguration", qconf);

            // Write the new configuration data to the XML file
            config.SaveAs(configFile, ConfigurationSaveMode.Full);

            Console.WriteLine(@"You data is saved.");
        }