Ejemplo n.º 1
0
        /// <summary>
        /// 转换成加密字符串。
        /// </summary>
        /// <param name="des">表示是否需要加密。</param>
        /// <returns></returns>
        public string ToDESString(bool des)
        {
            string s = string.Format("{0},{1},{2},{3},{4}", dataSource, initialCatalog, userID, password, trustedConnection);

            //des为真则加密。
            return(des ? DESCrypto.Encrypt(s) : s);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 从ini文件中读取。
        /// </summary>
        /// <param name="ia"></param>
        public void LoadFromIni(IniAccess ia)
        {
            string v = ia.ReadValue(FullName);

            if (NeedCrypto && v != null && v.Length > 0)
            {
                v = DESCrypto.Decrypt(v);
            }
            SetValue(v);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 保存至Ini文件。
        /// </summary>
        /// <param name="ia"></param>
        public void SaveToIni(IniAccess ia)
        {
            if (NeedSave)
            {
                string s = GetValue();

                if (NeedCrypto)
                {
                    s = DESCrypto.Encrypt(s);
                }

                ia.WriteValue(FullName, s);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 从指定加密的文件中加载数据。
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public bool LoadDesString(string path)
        {
            try
            {
                string data = FileHelper.LoadFromFile(path);

                if (data == null)
                {
                    return(false);
                }

                data = DESCrypto.Decrypt(data);

                LoadDataFromString(data);
            }
            catch { return(false); }
            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 对字符串进行解密。
        /// </summary>
        /// <param name="s"></param>
        /// <param name="des">表示是否需要解密。</param>
        public static SQLConnection FromDesString(string s, bool des)
        {
            SQLConnection cn = new SQLConnection();

            try
            {
                s = des ? DESCrypto.Decrypt(s) : s;
                string[] data = s.Split(',');
                cn.dataSource        = data[0];
                cn.initialCatalog    = data[1];
                cn.userID            = data[2];
                cn.password          = data[3];
                cn.trustedConnection = bool.Parse(data[4]);
            }
            catch { cn = null; }


            return(cn);
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 将连接字符串保存到INI文件中。用户名密码会自动加密。
 /// </summary>
 /// <param name="iniPath"></param>
 /// <returns></returns>
 public bool SaveToIni(string iniPath)
 {
     try
     {
         IniAccess.CreateFile(iniPath);
         IniAccess ia = new IniAccess(iniPath);
         ia.Section = "System";
         ia.WriteValue("DataSource", DataSource);
         ia.WriteValue("InitialCatalog", InitialCatalog);
         ia.WriteValue("UserID", DESCrypto.Encrypt(UserID));
         ia.WriteValue("Password", DESCrypto.Encrypt(Password));
         ia.WriteValue("TrustedConnection", TrustedConnection.ToString());
     }
     catch (Exception e1)
     {
         Console.WriteLine(e1.Message);
         return(false);
     }
     return(true);
 }
Ejemplo n.º 7
0
        /// <summary>
        /// 从给定的INI文件中读取连接字符串。用户名密码会自动加密。
        /// </summary>
        /// <param name="iniPath"></param>
        /// <returns></returns>
        public bool LoadFromIni(string iniPath)
        {
            try
            {
                IniAccess ia = new IniAccess(iniPath);
                ia.Section     = "System";
                DataSource     = ia.ReadValue("DataSource");
                InitialCatalog = ia.ReadValue("InitialCatalog");
                UserID         = ia.ReadValue("UserID");
                Password       = ia.ReadValue("Password");
                UserID         = DESCrypto.Decrypt(UserID);
                Password       = DESCrypto.Decrypt(Password);

                string s = ia.ReadValue("TrustedConnection");
                if (s != null && s.Length > 0)
                {
                    trustedConnection = bool.Parse(s);
                }
            }
            catch { return(false); }


            return(true);
        }