private void button2_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "Encrypted Password Manager Files (*.EPM)|*.EPM|" + "All files (*.*)|*.*"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) { using (PasswordForm PF = new PasswordForm(FormTranslationDictionary?["PasswordForm"])) { if (PF.ShowDialog() == DialogResult.OK) { baseName = saveFileDialog1.FileName; key = Convert_To_Key(PF.pass); currentIV = Generate_IV(); dataGridView1.Rows.Clear(); try { using (SQLiteConnection SC = new SQLiteConnection("DataSource=" + baseName)) { SC.Open(); using (SQLiteCommand cmd = new SQLiteCommand(SC)) { cmd.CommandText = @"create table if not exists Keys (KeyName blob not null primary key, Key blob not null, Login blob not null, URL blob)"; cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); cmd.CommandText = @"create table if not exists IV (Vector blob not null primary key)"; cmd.ExecuteNonQuery(); cmd.Parameters.Add("@iv", DbType.Binary).Value = currentIV; cmd.CommandText = @"insert into IV values (@iv)"; cmd.ExecuteNonQuery(); } } SortButton.Enabled = true; ascSort = true; SortButton.BackgroundImage = SortPic.Image; SaveTableButton.Enabled = false; hasUnsavedData = false; SortButton.BackgroundImage = SortPic.Image; Text = programName + ": " + Path.GetFileName(baseName); } catch { MessageBox.Show(CouldntCreateLabel.Text, ErrorLabel.Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } } }
void Open_File(string path) { using (PasswordForm PF = new PasswordForm(FormTranslationDictionary?["PasswordForm"])) { if (PF.ShowDialog() == DialogResult.OK) { baseName = path; key = Convert_To_Key(PF.pass); using (SQLiteConnection SC = new SQLiteConnection("Data Source=" + baseName)) { SC.Open(); using (SQLiteCommand cmd = new SQLiteCommand(SC)) { cmd.CommandType = CommandType.Text; cmd.CommandText = @"select Vector from IV"; using (SQLiteDataReader r = cmd.ExecuteReader()) { while (r.Read()) { currentIV = (byte[])r[0]; } } cmd.CommandText = @"select KeyName, Login, URL, Key from Keys"; bool decrypted = false; using (SQLiteDataReader r = cmd.ExecuteReader()) { while (r.Read()) { byte[] encstring = (byte[])r["KeyName"]; string keyname = Decrypt_String(encstring, key, currentIV); if (!decrypted) { dataGridView1.Rows.Clear(); decrypted = true; } dataGridView1.Rows.Add(); dataGridView1[0, dataGridView1.Rows.Count - 1].Value = keyname; encstring = (byte[])r["Login"]; dataGridView1[1, dataGridView1.Rows.Count - 1].Value = Decrypt_String(encstring, key, currentIV); encstring = (byte[])r["URL"]; dataGridView1[2, dataGridView1.Rows.Count - 1].Value = Decrypt_String(encstring, key, currentIV); encstring = (byte[])r["Key"]; dataGridView1[3, dataGridView1.Rows.Count - 1].Value = Decrypt_String(encstring, key, currentIV); } } } SortButton.Enabled = true; AddToTableButton.Enabled = true; ascSort = true; SortButton.BackgroundImage = SortPic.Image; SaveTableButton.Enabled = false; hasUnsavedData = false; Text = programName + ": " + Path.GetFileName(baseName); } } } }