Exemplo n.º 1
0
        public static void SetServer(ServerSettings server)
        {
            if (Exists(server.Name))
            {
                var xmlDoc = new XmlDocument();

                xmlDoc.Load(fileName);

                foreach (XmlNode expression in xmlDoc.SelectNodes(expressionXPath))
                {
                    if (server.Name == expression.Attributes["name"].Value)
                    {
                        using (var smc = new SymCryptography())
                        {
                            expression.Attributes["domain"].Value        = server.Domain;
                            expression.Attributes["ip"].Value            = server.IP;
                            expression.Attributes["isHttp"].Value        = server.IsHttp.ToString();
                            expression.Attributes["name"].Value          = server.Name;
                            expression.Attributes["password"].Value      = smc.Encrypt(server.Password);
                            expression.Attributes["path"].Value          = server.Path;
                            expression.Attributes["rootDirectory"].Value = server.RootDirectory;
                            expression.Attributes["username"].Value      = server.Username;

                            SaveXml(xmlDoc);

                            break;
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public static void AddServer(ServerSettings server)
        {
            if (!Exists(server.Name))
            {
                var xmlDoc = new XmlDocument();

                xmlDoc.Load(fileName);

                var newExpression = xmlDoc.CreateElement("server");

                using (var smc = new SymCryptography())
                {
                    newExpression.SetAttribute("domain", server.Domain);
                    newExpression.SetAttribute("ip", server.IP);
                    newExpression.SetAttribute("isHttp", server.IsHttp.ToString());
                    newExpression.SetAttribute("name", server.Name);
                    newExpression.SetAttribute("password", smc.Encrypt(server.Password));
                    newExpression.SetAttribute("path", server.Path);
                    newExpression.SetAttribute("rootDirectory", server.RootDirectory);
                    newExpression.SetAttribute("username", server.Username);

                    xmlDoc.SelectSingleNode(expressionXPath).ParentNode.AppendChild(newExpression);

                    SaveXml(xmlDoc);
                }
            }
        }
Exemplo n.º 3
0
        public static ServerSettings GetServerFromSettings(string name)
        {
            var server = new ServerSettings();

            var xmlDoc = new XmlDocument();

            xmlDoc.Load(fileName);

            foreach (XmlNode expression in xmlDoc.SelectNodes(expressionXPath))
            {
                if (name == expression.Attributes["name"].Value)
                {
                    using (var smc = new SymCryptography())
                    {
                        server.Domain        = expression.Attributes["domain"].Value;
                        server.IP            = expression.Attributes["ip"].Value;
                        server.IsHttp        = expression.Attributes["isHttp"].Value.BoolParse();
                        server.Name          = expression.Attributes["name"].Value;
                        server.Password      = smc.Decrypt(expression.Attributes["password"].Value);
                        server.Path          = expression.Attributes["path"].Value;
                        server.RootDirectory = expression.Attributes["rootDirectory"].Value;
                        server.Username      = expression.Attributes["username"].Value;
                        break;
                    }
                }
            }

            return(server);
        }
Exemplo n.º 4
0
        public frmMain()
        {
            InitializeComponent();

            m_client     = null;
            txtIP.Text   = m_hostIP;
            txtPort.Text = m_port.ToString();
            m_symCrpt    = new SymCryptography();
        }
Exemplo n.º 5
0
        public void EncryptAndDecryptTest()
        {
            string          plainText = "hello,my name is jsjs-gchao";
            SymCryptography crypt     = new SymCryptography();

            string cryptedText = crypt.Encrypt(plainText);

            string decryptedText = crypt.Decrypt(cryptedText);

            Assert.AreEqual(plainText, decryptedText, decryptedText);
        }
Exemplo n.º 6
0
        public void Save(Irc irc)
        {
            IConfig             server  = null;;
            string              host    = irc.Host;
            string              nick    = irc.Nick;
            string              user    = irc.Username;
            string              real    = irc.Realname;
            int                 port    = irc.Port;
            string              owner   = irc.Owner;
            string              nspass  = irc.NickPass;
            string              srvpass = irc.ServerPass;
            Stack <ChannelData> buffer  = irc.ChannelBuffer;

            if (!string.IsNullOrEmpty(nspass))
            {
                nspass = new SymCryptography(SymCryptography.ServiceProviderEnum.Rijndael).Encrypt(nspass);
            }

            // Last known code
            RFC1459.ReplyCode lkc    = irc.Code;
            ConsoleColor      colour = irc.Colour;

            if (config.Configs[irc.Server] == null)
            {
                server = config.AddConfig(irc.Server);
            }
            else
            {
                server = config.Configs[irc.Server];
            }

            server.Set("Host", host);
            server.Set("Port", port);
            server.Set("Nick", nick);
            server.Set("Server_Password", srvpass);
            server.Set("Username", user);
            server.Set("Realname", real);
            server.Set("NickPassword", nspass);
            server.Set("Owner", owner);
            server.Set("LastKnownCode", ( int )lkc);
            server.Set("Colour", ( int )colour);
            server.Set("MainChannel", "{nokey}");
            server.Set("MainKey", "{nokey}");

            if (buffer.Count > 0)
            {
                server.Set("Channels", string.Join(",", buffer.ToArray( )));
            }

            config.Save( );
        }
Exemplo n.º 7
0
        static void Main(string[] args)
        {
            string          plainText = "hello,my name is jsjs-gchao";
            SymCryptography crypt     = new SymCryptography();

            string cryptedText = crypt.Encrypt(plainText);

            string decryptedText = crypt.Decrypt(cryptedText);

            Console.WriteLine(string.Format("PlainText:{0}", plainText));
            Console.WriteLine(string.Format("cryptedText:{0}", cryptedText));

            Console.ReadKey();
        }
Exemplo n.º 8
0
        public Irc Read(string server)
        {
            Irc          _irc;
            string       host, nick, password, srvPass, owner, user, real, channel, key, additional;
            int          port;
            ConsoleColor colour;

            RFC1459.ReplyCode lkc;
            IConfig           irc = config.Configs[server];

            nick     = irc.GetString("Nick");
            real     = irc.GetString("Realname");
            user     = irc.GetString("Username");
            host     = irc.GetString("Host");
            srvPass  = irc.GetString("Server_Password");
            port     = irc.GetInt("Port");
            owner    = irc.GetString("Owner");
            password = irc.GetString("NickPassword");
            if (!string.IsNullOrEmpty(password))
            {
                password = new SymCryptography(SymCryptography.ServiceProviderEnum.Rijndael).Decrypt(password);
            }
            lkc        = (RFC1459.ReplyCode)irc.GetInt("LastKnownCode");
            colour     = ( ConsoleColor )irc.GetInt("Colour");
            channel    = irc.GetString("MainChannel");
            key        = irc.GetString("MainKey");
            additional = irc.GetString("Channels");

            Stack <ChannelData> chanBuffer = new Stack <ChannelData> ( );

            foreach (string ch in additional.Split(','))
            {
                string[] chankey = ch.Split(':');
                chanBuffer.Push(new ChannelData( )
                {
                    Channel = chankey[0], Key = chankey[1]
                });
            }

            _irc = new Irc(nick, real, user, password, host, "", port, lkc, colour, channel, key);
            _irc.ChannelBuffer = chanBuffer;

            return(_irc);
        }