private void NewAcc(string name, string pin, string key)//create new acc { string res, textToEncrypt; string cryptoAccKey = null; string cryptoBinKey = null; DialogResult dialogResult = MessageBox.Show("Jméno: " + name + Environment.NewLine + "PIN: " + pin + Environment.NewLine + "Správně?", "Ověření", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { string accsPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\accs"; string binPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\bin"; if (!Directory.Exists(binPath)) // jestli existuje slozka bin { Directory.CreateDirectory(binPath); //vytvorit } if (!Directory.Exists(accsPath)) // jestli existuje slozka s uzivateli { Directory.CreateDirectory(accsPath); //vytvorit } if (!File.Exists(accsPath + "\\key.xml"))//vytvori klic pro spravu uctu { RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); StreamWriter SaveKey = new StreamWriter(accsPath + "\\key.xml"); SaveKey.Write(cryptoAccKey = (RSA.ToXmlString(true))); SaveKey.Close(); } else//nebo precte pokud ma { try { RSACryptoServiceProvider RSAacc = new RSACryptoServiceProvider(); StreamReader OpenKey = new StreamReader(accsPath + "\\key.xml"); cryptoAccKey = OpenKey.ReadToEnd(); OpenKey.Close(); RSAacc.FromXmlString(cryptoAccKey); } catch//pokud precte a bude v key.xml chyba { MessageBox.Show("Chyba v souboru: " + accsPath + "\\key.xml"); Application.OpenForms[0].Show(); this.Hide(); } } if (!File.Exists(accsPath + "\\" + name + ".dll"))//zda neexistuje soubor s takovym uctem { res = ""; textToEncrypt = name + ";" + pin + ";" + key; res = Crypter.Encrypt(textToEncrypt, cryptoAccKey);//zasifruje StreamWriter strmAccWrite = new StreamWriter(accsPath + "\\" + name + ".dll"); strmAccWrite.Write(res); strmAccWrite.Close(); while (true) { if (!Directory.Exists(binPath + "\\" + key + "\\")) //zepta se jestli je slozka a soubor pro ulozeni dat { Directory.CreateDirectory(binPath + "\\" + key + "\\"); //vytvori se direktorie #region ziskani klice cryptoBinKey if (!File.Exists(binPath + "\\" + key + "\\" + "key.xml"))//vytvori se unikatni klic pro slozku s hesly { Directory.CreateDirectory(binPath + "\\" + key); RSACryptoServiceProvider RSAbin = new RSACryptoServiceProvider(); StreamWriter SaveKey = new StreamWriter(binPath + "\\" + key + "\\" + "key.xml"); SaveKey.Write(cryptoBinKey = (RSAbin.ToXmlString(true))); SaveKey.Close(); } else { try { RSACryptoServiceProvider RSAbin = new RSACryptoServiceProvider(); StreamReader OpenKey = new StreamReader(binPath + "\\" + key + "\\" + "key.xml"); cryptoBinKey = OpenKey.ReadToEnd(); OpenKey.Close(); RSAbin.FromXmlString(cryptoAccKey); } catch//pokud precte a bude v key.xml chyba { MessageBox.Show("Chyba v souboru: " + binPath + "\\" + key + "\\" + "key.xml"); Application.OpenForms[0].Show(); this.Hide(); } } #endregion Directory.CreateDirectory(binPath + "\\" + key + "\\" + "1");//vytvori se direktorie string[] data = new string[] { " ", " ", " ", " " }; for (int i = 0; i < 4; i++) { StreamWriter strmBinWrite = new StreamWriter(binPath + "\\" + key + "\\1\\" + (i + 1).ToString() + ".dll"); strmBinWrite.Write(Crypter.Encrypt(data[i], cryptoBinKey)); strmBinWrite.Close(); } StreamWriter strmAccWrite2 = new StreamWriter(accsPath + "\\" + name + ".dll"); res = ""; textToEncrypt = name + ";" + pin + ";" + key; res = Crypter.Encrypt(textToEncrypt, cryptoAccKey); strmAccWrite2.Write(res); strmAccWrite2.Close(); MessageBox.Show("Účet je vytvořen :)"); if (Application.OpenForms[0].Name == "Form1") { Application.OpenForms[0].Show(); } this.Hide(); break; } else { k = new generate(); key = k.gen(true, true, true, true, 25); } } } else { MessageBox.Show("Účet jíž existuje, vytvořte jiný"); } } else if (dialogResult == DialogResult.No) { txtPIN.Text = ""; txtUsername.Text = ""; txtVerifyPIN.Text = ""; txtPIN.ForeColor = Color.Red; txtVerifyPIN.ForeColor = Color.Red; txtUsername.ForeColor = Color.Red; } }
private void BtnLogIn_Click(object sender, EventArgs e) { //cesta do slozek string accsPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\accs"; string binPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\bin"; string decryptedContent = null; #region inicializace klice pro accs try { RSACryptoServiceProvider RSAacc = new RSACryptoServiceProvider(); StreamReader OpenKey = new StreamReader(accsPath + "\\key.xml"); cryptoAccKey = OpenKey.ReadToEnd(); OpenKey.Close(); RSAacc.FromXmlString(cryptoAccKey); } catch//pokud precte a bude v key.xml chyba { MessageBox.Show("Chyba v souboru: " + accsPath + "\\key.xml"); Application.OpenForms[0].Show(); this.Hide(); } #endregion if (File.Exists(accsPath + "\\" + txtUsername.Text + ".dll")) { StreamReader strmReadAcc = new StreamReader(accsPath + "\\" + txtUsername.Text + ".dll"); decryptedContent = Crypter.Decrypt(strmReadAcc.ReadToEnd(), cryptoAccKey);//rozsifruje string[] accFile = new string[3]; accFile[0] = decryptedContent.Split(';')[0]; accFile[1] = decryptedContent.Split(';')[1]; accFile[2] = decryptedContent.Split(';')[2]; strmReadAcc.Close(); string name = accFile[0]; string pin = accFile[1]; string key = accFile[2]; #region inicializace klice pro bin try { RSACryptoServiceProvider RSAbin = new RSACryptoServiceProvider(); StreamReader OpenKey = new StreamReader(binPath + "\\" + key + "\\" + "key.xml"); cryptoBinKey = OpenKey.ReadToEnd(); OpenKey.Close(); RSAbin.FromXmlString(cryptoAccKey); } catch//pokud precte a bude v key.xml chyba { MessageBox.Show("Chyba v souboru: " + binPath + "\\" + key + "\\" + "key.xml"); Application.OpenForms[0].Show(); this.Hide(); } #endregion if (pin == txtPIN.Text) { DirectoryInfo dd = new DirectoryInfo(binPath + "\\" + key); //vezme data z direktorie DirectoryInfo[] Folders = dd.GetDirectories(); //Getting directories if (Folders.Count() >= 1) { bool jestliMaAlesponJedenDLL = false; for (int j = 0; j < Folders.Count(); j++) { DirectoryInfo df = new DirectoryInfo(binPath + "\\" + key + "\\" + Folders[j]); //vezme data z direktorie FileInfo[] Files = df.GetFiles("*.dll"); //Getting .dll files if (Files.Count() >= 1) { jestliMaAlesponJedenDLL = true; } } if (jestliMaAlesponJedenDLL == true) { PullForm pullForm = new DokaPass.PullForm(key, cryptoAccKey, cryptoBinKey, txtUsername.Text, this.Width, this.Height, this.Location.X, this.Location.Y); pullForm.Show(); txtPIN.Text = ""; txtUsername.Text = ""; if (Application.OpenForms[0].Name == "Form1") { Application.OpenForms[0].Hide(); } this.Hide(); } else { MessageBox.Show("Data s heslama nejsou"); txtPIN.Text = ""; txtUsername.Text = ""; } } else { MessageBox.Show("Data s heslama nejsou"); txtPIN.Text = ""; txtUsername.Text = ""; } } else { MessageBox.Show("Špatný pin"); txtPIN.Text = ""; } } else { MessageBox.Show(txtUsername.Text + " neexistuje, zadejte správně jméno. :("); txtPIN.Text = ""; txtUsername.Text = ""; } }
private void BtnDelete_Click(object sender, EventArgs e) { foreach (DataGridViewRow row in dtGridView.SelectedRows) { DialogResult msgbx = MessageBox.Show("Chcete odstránít řádek?", "", MessageBoxButtons.YesNo); if (msgbx == DialogResult.Yes) { string binPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\bin"; DirectoryInfo di = new DirectoryInfo(binPath + "\\" + key); //vezme data z direktorie DirectoryInfo[] folders = di.GetDirectories(); for (int i = 0; i < folders.Count(); i++) { if (i == row.Index) { DirectoryInfo dd = new DirectoryInfo(binPath + "\\" + key + "\\" + folders[i]); foreach (FileInfo file in dd.GetFiles()) { file.Delete(); } folders[i].Delete(true); if (folders.Count() <= 1) { for (int j = 0; j < 4; j++) { switch (j) { case 0: if (!Directory.Exists(binPath + "\\" + key + "\\" + (i + 1).ToString())) { Directory.CreateDirectory(binPath + "\\" + key + "\\" + (i + 1).ToString()); //jestli neexistuje slozka } StreamWriter strmZapis1 = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (j + 1).ToString() + ".dll"); strmZapis1.Write(Crypter.Encrypt((" "), cryptoBinKey)); strmZapis1.Close(); break; case 1: if (!Directory.Exists(binPath + "\\" + key + "\\" + (i + 1).ToString())) { Directory.CreateDirectory(binPath + "\\" + key + "\\" + (i + 1).ToString()); //jestli neexistuje slozka } StreamWriter strmZapis2 = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (j + 1).ToString() + ".dll"); strmZapis2.Write(Crypter.Encrypt((" "), cryptoBinKey)); strmZapis2.Close(); break; case 2: if (!Directory.Exists(binPath + "\\" + key + "\\" + (i + 1).ToString())) { Directory.CreateDirectory(binPath + "\\" + key + "\\" + (i + 1).ToString()); //jestli neexistuje slozka } StreamWriter strmZapis3 = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (j + 1).ToString() + ".dll"); strmZapis3.Write(Crypter.Encrypt((" "), cryptoBinKey)); strmZapis3.Close(); break; case 3: if (!Directory.Exists(binPath + "\\" + key + "\\" + (i + 1).ToString())) { Directory.CreateDirectory(binPath + "\\" + key + "\\" + (i + 1).ToString()); //jestli neexistuje slozka } StreamWriter strmZapis4 = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (j + 1).ToString() + ".dll"); strmZapis4.Write(Crypter.Encrypt((" "), cryptoBinKey)); strmZapis4.Close(); break; } } } } } dtGridView.Refresh(); DataGridView_Refresh(); TxtName_SetText(); TxtPass_SetText(); TxtUsername_SetText(); TxtComments_SetText(); } } }
private void DataGridView_Refresh() { List <string> dtgridViewData = new List <string>(); dtGridView.Rows.Clear(); dtGridView.ColumnCount = 4; dtGridView.Columns[0].Name = "Název:"; dtGridView.Columns[1].Name = "Username:"******"Heslo:"; dtGridView.Columns[3].Name = "Poznámka:"; string binPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\bin"; DirectoryInfo dd = new DirectoryInfo(binPath + "\\" + key); //vezme data z direktorie DirectoryInfo[] Folders = dd.GetDirectories(); //Getting all folders dtGridView.Rows.Clear(); for (int i = 0; i < Folders.Count(); i++) { DirectoryInfo df = new DirectoryInfo(binPath + "\\" + key + "\\" + Folders[i]); //vezme data z direktorie FileInfo[] Files = df.GetFiles("*.dll"); //Getting all .dll folders if (Files.Count() >= 1) { string[] contentSouboru = new string[4]; for (int j = 0; j < Files.Count(); j++) { switch (Files[j].ToString()) { case "1.dll": StreamReader strmR1 = new StreamReader(binPath + "\\" + key + "\\" + Folders[i] + "\\" + Files[j].ToString()); string data1 = null; data1 = strmR1.ReadToEnd(); if (data1 != "" || data1 != " ") { contentSouboru[0] = Crypter.Decrypt(data1, cryptoBinKey); } else { contentSouboru[0] = ""; } strmR1.Close(); break; case "2.dll": StreamReader strmR2 = new StreamReader(binPath + "\\" + key + "\\" + Folders[i] + "\\" + Files[j].ToString()); string data2 = null; data2 = strmR2.ReadToEnd(); if (data2 != "" || data2 != " ") { contentSouboru[1] = Crypter.Decrypt(data2, cryptoBinKey); } else { contentSouboru[1] = ""; } strmR2.Close(); break; case "3.dll": StreamReader strmR3 = new StreamReader(binPath + "\\" + key + "\\" + Folders[i] + "\\" + Files[j].ToString()); string data3 = null; data3 = strmR3.ReadToEnd(); if (data3 != "" || data3 != " ") { contentSouboru[2] = Crypter.Decrypt(data3, cryptoBinKey); } else { contentSouboru[2] = ""; } strmR3.Close(); break; case "4.dll": StreamReader strmR4 = new StreamReader(binPath + "\\" + key + "\\" + Folders[i] + "\\" + Files[j].ToString()); string data4 = null; data4 = strmR4.ReadToEnd(); if (data4 != "" || data4 != " ") { contentSouboru[3] = Crypter.Decrypt(data4, cryptoBinKey); } else { contentSouboru[3] = ""; } strmR4.Close(); break; } } try { if ((contentSouboru[0] != "" && contentSouboru[0] != " ") && (contentSouboru[1] != "" && contentSouboru[1] != " ") && (contentSouboru[2] != "" && contentSouboru[2] != " ") && (contentSouboru[3] != "" && contentSouboru[3] != " ")) { dtGridView.Rows.Add(contentSouboru[0], contentSouboru[1], contentSouboru[2], contentSouboru[3]); } } catch { } } } dtGridView.Refresh(); textbox_fill(); }
private void DataGridView_Upload() { if (txtWebPageName.ForeColor == Color.Gray && txtUsername.ForeColor == Color.Gray && txtPass.ForeColor == Color.Gray && txtComments.ForeColor == Color.Gray) { MessageBox.Show("Zadej všechny údaje."); } else { if (txtWebPageName.ForeColor != Color.Gray || txtUsername.ForeColor != Color.Gray || txtPass.ForeColor != Color.Gray || txtComments.ForeColor != Color.Gray) { dtGridView.Rows.Add(txtWebPageName.Text, txtUsername.Text, txtPass.Text, txtComments.Text); //////////////////////////////////////////////////////////// ulozeni z datagrid do souboru string binPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\bin"; for (int i = 0; i < dtGridView.RowCount; i++) { for (int j = 0; j < 4; j++) { switch (j) { case 0: if (!Directory.Exists(binPath + "\\" + key + "\\" + (i + 1).ToString())) { Directory.CreateDirectory(binPath + "\\" + key + "\\" + (i + 1).ToString()); //jestli neexistuje slozka } StreamWriter strmZapis1 = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (j + 1).ToString() + ".dll"); strmZapis1.Write(Crypter.Encrypt(dtGridView.Rows[i].Cells[0].Value.ToString(), cryptoBinKey)); strmZapis1.Close(); break; case 1: if (!Directory.Exists(binPath + "\\" + key + "\\" + (i + 1).ToString())) { Directory.CreateDirectory(binPath + "\\" + key + "\\" + (i + 1).ToString()); //jestli neexistuje slozka } StreamWriter strmZapis2 = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (j + 1).ToString() + ".dll"); strmZapis2.Write(Crypter.Encrypt(dtGridView.Rows[i].Cells[1].Value.ToString(), cryptoBinKey)); strmZapis2.Close(); break; case 2: if (!Directory.Exists(binPath + "\\" + key + "\\" + (i + 1).ToString())) { Directory.CreateDirectory(binPath + "\\" + key + "\\" + (i + 1).ToString()); //jestli neexistuje slozka } StreamWriter strmZapis3 = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (j + 1).ToString() + ".dll"); strmZapis3.Write(Crypter.Encrypt(dtGridView.Rows[i].Cells[2].Value.ToString(), cryptoBinKey)); strmZapis3.Close(); break; case 3: if (!Directory.Exists(binPath + "\\" + key + "\\" + (i + 1).ToString())) { Directory.CreateDirectory(binPath + "\\" + key + "\\" + (i + 1).ToString()); //jestli neexistuje slozka } StreamWriter strmZapis4 = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (j + 1).ToString() + ".dll"); strmZapis4.Write(Crypter.Encrypt(dtGridView.Rows[i].Cells[3].Value.ToString(), cryptoBinKey)); strmZapis4.Close(); break; } } } DisplayMode = "view"; AfterButtonClick(); } else { MessageBox.Show("Napíš všechny údaje"); } } }
private void DataGridView_Edit() { string binPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\bin"; if (dtGridView.SelectedRows == null) { MessageBox.Show("Nelze nic upravit"); } else { foreach (DataGridViewRow row in dtGridView.SelectedRows) { DirectoryInfo di = new DirectoryInfo(binPath + "\\" + key); //vezme data z direktorie DirectoryInfo[] folders = di.GetDirectories(); if (txtWebPageName.Text == "") { txtWebPageName.Text = " "; } for (int i = 0; i <= dtGridView.RowCount; i++) { if (row.Index == i) { StreamWriter strmUprava = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (1).ToString() + ".dll"); strmUprava.Write(Crypter.Encrypt(txtWebPageName.Text, cryptoBinKey)); strmUprava.Close(); } } if (txtUsername.Text == "") { txtUsername.Text = " "; } for (int i = 0; i <= dtGridView.RowCount; i++) { if (row.Index == i) { StreamWriter strmUprava = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (2).ToString() + ".dll"); strmUprava.Write(Crypter.Encrypt(txtUsername.Text, cryptoBinKey)); strmUprava.Close(); } } if (txtPass.Text == "") { txtPass.Text = " "; } for (int i = 0; i <= dtGridView.RowCount; i++) { if (row.Index == i) { StreamWriter strmUprava = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (3).ToString() + ".dll"); strmUprava.Write(Crypter.Encrypt(txtPass.Text, cryptoBinKey)); strmUprava.Close(); } } if (txtComments.Text == "") { txtComments.Text = " "; } for (int i = 0; i <= dtGridView.RowCount; i++) { if (row.Index == i) { StreamWriter strmUprava = new StreamWriter(binPath + "\\" + key + "\\" + (i + 1).ToString() + "\\" + (4).ToString() + ".dll"); strmUprava.Write(Crypter.Encrypt(txtComments.Text, cryptoBinKey)); strmUprava.Close(); } } } DisplayMode = "view"; AfterButtonClick(); } }