Esempio n. 1
0
 public AddKeyEventArgs(int CommonID, string[] Record_Pathes, KeyFileObject New_Record, bool Save_Pwd)
 {
     this.CommonID = CommonID;
     this.Record_Pathes = Record_Pathes;
     this.New_Record = New_Record;
     this.Save_Pwd = Save_Pwd;
 }
Esempio n. 2
0
        public void ValidateNewRecord(KeyFileObject New_Record, bool Add_ComboBox)
        {
            List<string> Existed_Pathes = new List<string>();
            Dictionary<string, KeyFileObject> dic = GetFileInfo();
            List<string> MachineName_Pathes = new List<string>();
            List<string> UNC_Pathes = new List<string>();
            foreach (KeyValuePair<string, KeyFileObject> path in dic)
            {
                if (path.Key.StartsWith("\\") || path.Key.StartsWith("ftp://"))
                {
                    UNC_Pathes.Add(path.Key.ToLower());
                }
                else
                {
                    MachineName_Pathes.Add(path.Key.ToLower());
                }
            }

            //Check if existed path list contain the new path
            bool PathIsMachineName = false;
            if (!(New_Record.Path.Contains("\\") || New_Record.Path.ToLower().StartsWith("ftp://")))
                PathIsMachineName = true;

            if (PathIsMachineName)
            {
                if (MachineName_Pathes.Contains(New_Record.Path.ToLower()))
                    Existed_Pathes.Add(New_Record.Path.ToLower());
            }
            else
            {
                foreach (string unc_path in UNC_Pathes)
                {
                    if(unc_path.Contains(New_Record.Path.ToLower()))
                    {
                        Existed_Pathes.Add(unc_path);
                    }
                    else if (New_Record.Path.ToLower().Contains(unc_path))
                    {
                        Existed_Pathes.Add(unc_path);
                    }
                }
            }

            OnAddKeyEvent(this, new AddKeyEventArgs(this.ID, Existed_Pathes.ToArray(), New_Record, Add_ComboBox)); //For refresh ComboBox in DR_Tool Form
        }
Esempio n. 3
0
 public void AddKeyDictionary(KeyFileObject new_record)
 {
     Dictionary<string, KeyFileObject> dic = this.GetFileInfo();
     dic.Add(new_record.Path.ToLower(), new_record);
     isRefresh = false;
 }
Esempio n. 4
0
        public void RefreshFile(string path)
        {
            //if key file is not sorted, then rewrite the key file
            if (!isRefresh)
            {
                List<KeyFileObject> list = new List<KeyFileObject>();
                CredentialDic = new Dictionary<string, KeyFileObject>();
                if (!File.Exists(path))
                    return;

                string strLine = "";
                FileInfo f = new FileInfo(path);
                StreamReader srFile = f.OpenText();
                while ((strLine = srFile.ReadLine()) != null)
                {
                    if (strLine.Trim().Length > 0)
                    {
                        if (strLine != EOF_Mark)
                        {
                            string[] strWord = strLine.Split('\t');
                            KeyFileObject key = ReadAESKey(strWord[0], strWord[1]);
                            if (key == null)
                            {
                                srFile.Close();
                                File.Delete(path);
                                return;
                            }
                            list.Add(key);
                        }
                        else
                        {
                            list.Add(new KeyFileObject(EOF_Mark, "", "", "", ""));
                        }
                    }
                }
                srFile.Close();

                if (list.Count != 0)
                {
                    KeyFileObject EOF_Mark_Object = new KeyFileObject(EOF_Mark, "", "", "", "");
                    if (list[list.Count - 1] == EOF_Mark_Object)
                    {
                        list.Remove(EOF_Mark_Object);
                        list.Sort();
                        foreach (KeyFileObject record in list)
                        {
                            CredentialDic.Add(record.Path, record);
                        }
                    }
                    else
                    {
                        list.Remove(EOF_Mark_Object);
                        list.Sort();

                        File.Delete(path);
                        StreamWriter w = File.AppendText(path);
                        AESEncrypt AES = new AESEncrypt();
                        foreach (KeyFileObject record in list)
                        {
                            CredentialDic.Add(record.Path, record);
                            w.WriteLine(record.Path + "\t" + AES.Encrypt_AES(record));
                        }
                        w.WriteLine(EOF_Mark);
                        w.Flush();
                        w.Close();
                    }
                }
            }
            isRefresh = true;
        }
Esempio n. 5
0
 //Customize by John
 public String Encrypt_AES(KeyFileObject key)
 {
     return Encrypt_AES(key.Path + "\t" + key.MethodType + "\t" + key.Domain + "\t" + key.Username + "\t" + key.Password + "\t" + "@" + System.Windows.Forms.SystemInformation.ComputerName);
 }