private void buttonChange_Click(object sender, EventArgs e) { if (listViewMain.SelectedItems.Count == 1) { ManageItems manageItems = new ManageItems(this); AES256 AES = new AES256(); if (manageItems.CheckInputData() && MessageBox.Show("정말로 변경하시겠습니까?", "질문", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string[] arrItems = { textBoxSiteName.Text, textBoxSiteAddress.Text, textBoxID.Text, textBoxMemo.Text, textBoxPassword.Text }; arrItems[4] = AES.EncryptString(arrItems[4]); foreach (ListViewItem LVI in listViewMain.SelectedItems) { LVI.Text = arrItems[0]; LVI.SubItems[1].Text = arrItems[1]; LVI.SubItems[2].Text = arrItems[2]; LVI.SubItems[3].Text = arrItems[3]; LVI.Tag = arrItems[4]; manageItems.Change(LVI.Index, arrItems); } manageItems.SaveFile(); } } else { MessageBox.Show("변경하실 항목을 선택해 주세요.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
private void buttonAdd_Click(object sender, EventArgs e) { ManageItems manageItems = new ManageItems(this); AES256 AES = new AES256(); string[] arrItems = { textBoxSiteName.Text, textBoxSiteAddress.Text, textBoxID.Text, textBoxMemo.Text, textBoxPassword.Text }; arrItems[4] = AES.EncryptString(arrItems[4]); if (manageItems.CheckInputData()) { ListViewItem LVI = new ListViewItem(); LVI.Text = arrItems[0]; LVI.SubItems.Add(arrItems[1]); LVI.SubItems.Add(arrItems[2]); LVI.SubItems.Add(arrItems[3]); LVI.Tag = arrItems[4]; listViewMain.Items.Add(LVI); manageItems.Add(arrItems); manageItems.SaveFile(); } }
private void buttonChange_Click(object sender, EventArgs e) { #region 입력값 검증 if (textBoxChangeKey.Text == "") { MessageBox.Show("키 값을 입력해 주세요.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxChangeKey.Focus(); return; } if (textBoxChangeKey.Text != textBoxChangeConKey.Text) { MessageBox.Show("입력하신 키 값이 서로 일치하지 않습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxChangeConKey.Focus(); return; } if (textBoxChangePassword.Text == "") { MessageBox.Show("비밀번호를 입력해 주세요.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxChangePassword.Focus(); return; } if (textBoxChangePassword.Text != textBoxChangeConPassword.Text) { MessageBox.Show("입력하신 비밀번호가 서로 일치하지 않습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); textBoxChangeConPassword.Focus(); return; } #endregion if (MessageBox.Show("정말로 변경하시겠습니까?", "질문", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { AES256 AES = new AES256(); string hashString = null; byte[] encryptedBytes = null; // 리스트뷰 정보 새로 암호화 if (mainForm.listViewMain.Items.Count > 0) { using (MemoryStream MS = new MemoryStream()) { using (StreamWriter SW = new StreamWriter(MS, Encoding.UTF8)) { List <string> list = new List <string>(); foreach (ListViewItem LVI in mainForm.listViewMain.Items) { list.Add(LVI.Text); list.Add(LVI.SubItems[1].Text); list.Add(LVI.SubItems[2].Text); list.Add(LVI.SubItems[3].Text); list.Add(AES.DecryptString((string)LVI.Tag)); } AES.KeyString = textBoxChangeKey.Text; AES.SaltBytes = CommonData.EncryptSalt; for (int i = 0; i < list.Count; i += 5) { SW.WriteLine(list[i]); SW.WriteLine(list[i + 1]); SW.WriteLine(list[i + 2]); SW.WriteLine(list[i + 3]); SW.WriteLine(AES.EncryptString(list[i + 4])); SW.Flush(); } encryptedBytes = AES.EncryptByte(MS.ToArray()); File.WriteAllBytes(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.DataFile), encryptedBytes); } } } else { AES.KeyString = textBoxChangeKey.Text; AES.SaltBytes = CommonData.EncryptSalt; File.Delete(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.DataFile)); } // 비밀번호 암호화 hashString = Convert.ToBase64String(SHA512.Create().ComputeHash(Encoding.UTF8.GetBytes(CommonData.HashSalt + textBoxChangePassword.Text))); encryptedBytes = AES.EncryptByte(Encoding.UTF8.GetBytes(hashString + textBoxChangePassword.Text)); // 정보 저장 File.WriteAllBytes(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.PasswordFile), encryptedBytes); // 성공 메세지 MessageBox.Show("비밀번호가 정상적으로 변경되었습니다. \n프로그램을 다시 실행해 주세요.", "알림", MessageBoxButtons.OK, MessageBoxIcon.Information); Application.Exit(); } }