private void WritePskFile() { byte[] table = TableToArray(); // ======== // ENCRIPT // ======== Encription encription = new Encription(encriptionKey); table = encription.Encript(table); try { FileStream stream = File.Create(openedFile); stream.Write(table, 0, table.Length); stream.Close(); needSave = false; this.Text = shortFileName + DEMOCAPTION; } catch { MessageBox.Show("Не удалось записать файл!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); this.Text = "Password Keeper" + DEMOCAPTION; } }
private void ReadPskFile() { byte[] buffer = new byte[1]; try { FileStream stream = File.Open(openedFile, FileMode.Open); buffer = new byte[stream.Length]; stream.Read(buffer, 0, buffer.Length); stream.Close(); } catch { openedFile = string.Empty; shortFileName = string.Empty; MessageBox.Show("Не удалось прочитать файл!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // ============== // DECRIPT buffer // ============== Encription encription = new Encription(encriptionKey); buffer = encription.Decript(buffer); bool transferIsOk = TableFromArray(buffer); if (transferIsOk) { // hide/show passwords if (showAllPass) { for (int i = 0; i < dataGridMain.RowCount; i++) { dataGridMain.Rows[i].Cells[2].Value = dataGridMain.Rows[i].Cells[4].Value; } } else { for (int i = 0; i < dataGridMain.RowCount; i++) { dataGridMain.Rows[i].Cells[2].Value = HIDEPASSWORDSTRING; } } } else { openedFile = string.Empty; shortFileName = string.Empty; } }