コード例 #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;
                        }
                    }
                }
            }
        }
コード例 #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);
                }
            }
        }
コード例 #3
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);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: guochao2299/ChatRoom
        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();
        }
コード例 #5
0
ファイル: QueryManager.cs プロジェクト: AseelAL/TEMP
//CREATE

        public string CreateUser(User aUser)
        {
            string     res         = "-1";
            HttpCookie userCookies = new HttpCookie("BHCUser");
            string     userName    = userCookies.Name;

            SqlConnection aConnection = DBMgr.GetSQLConnection();

            try
            {
                aConnection.Open();
                SqlCommand myCmnd = aConnection.CreateCommand();

                myCmnd.CommandText = @"insert into [Sys_User] ([User Name],[Password] ,[Type], [Dummy Password], [Created Date],[Created by]) values ('"
                                     + aUser.UserName + "'" + ",' "
                                     + CryptManager.Encrypt(aUser.Password) + "', "
                                     + (int)aUser.Type + ", 1, GETDATE()," + " '" + userName + "');" +
                                     @"select ID from Sys_User where [User Name] = '" + aUser.UserName + "'";

                SqlDataReader aReader = myCmnd.ExecuteReader();
                if (aReader.Read())
                {
                    res = aReader["ID"].ToString();
                }

                aReader.Close();
            }
            catch (SqlException se)
            {
                res = "-1";
                aConnection.Close();
                throw (se);
            }

            aConnection.Close();
            return(res);
        }