Exemple #1
0
        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);
            }
        }
Exemple #2
0
        private void listViewMain_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (listViewMain.SelectedItems.Count > 0)
            {
                AES256 AES = new AES256();
                checkBoxShowPassword.Checked = false;

                foreach (ListViewItem LVI in listViewMain.SelectedItems)
                {
                    textBoxSiteName.Text    = LVI.Text;
                    textBoxSiteAddress.Text = LVI.SubItems[1].Text;
                    textBoxID.Text          = LVI.SubItems[2].Text;
                    textBoxMemo.Text        = LVI.SubItems[3].Text;
                    textBoxPassword.Text    = AES.DecryptString((string)LVI.Tag);
                }
            }
            else
            {
                textBoxSiteName.Text    = "";
                textBoxSiteAddress.Text = "";
                textBoxID.Text          = "";
                textBoxMemo.Text        = "";
                textBoxPassword.Text    = "";
            }
        }
Exemple #3
0
        // 파일로 정보 저장
        public void SaveFile()
        {
            if (mainForm.listViewMain.Items.Count > 0)
            {
                using (MemoryStream MS = new MemoryStream())
                {
                    using (StreamWriter SW = new StreamWriter(MS, Encoding.UTF8))
                    {
                        AES256 AES            = new AES256();
                        byte[] encryptedBytes = null;

                        foreach (DataRow row in dataTable.Rows)
                        {
                            SW.WriteLine(row["사이트 이름"].ToString());
                            SW.WriteLine(row["사이트 주소"].ToString());
                            SW.WriteLine(row["아이디"].ToString());
                            SW.WriteLine(row["메모"].ToString());
                            SW.WriteLine(row["Password"].ToString());
                            SW.Flush();
                        }

                        encryptedBytes = AES.EncryptByte(MS.ToArray());
                        File.WriteAllBytes(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.DataFile), encryptedBytes);
                    }
                }
            }
        }
Exemple #4
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            AES256 AES = new AES256();
            string hashString = null; byte[] encryptedBytes = null;

            // 암호화 기본 설정
            AES.KeyString = textBoxKey.Text;
            AES.SaltBytes = CommonData.EncryptSalt;

            // 비밀번호 암호화
            hashString     = Convert.ToBase64String(SHA512.Create().ComputeHash(Encoding.UTF8.GetBytes(CommonData.HashSalt + textBoxPassword.Text)));
            encryptedBytes = AES.EncryptByte(Encoding.UTF8.GetBytes(hashString + textBoxPassword.Text));

            // 정보 로드 및 배열 비교 준비
            byte[] loadData         = File.ReadAllBytes(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.PasswordFile));
            IStructuralEquatable SE = loadData;

            // 배열 서로 비교
            if (SE.Equals(encryptedBytes, StructuralComparisons.StructuralEqualityComparer))
            {
                frmMain form = new frmMain();
                form.Show(); this.Hide();
            }
            else
            {
                MessageBox.Show("로그인에 실패하였습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                Application.Exit();
            }
        }
Exemple #5
0
        private void buttonCreatePassword_Click(object sender, EventArgs e)
        {
            #region 입력값 검증
            if (textBoxKey.Text == "")
            {
                MessageBox.Show("키 값을 입력해 주세요.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                textBoxKey.Focus(); return;
            }

            if (textBoxKey.Text != textBoxConKey.Text)
            {
                MessageBox.Show("입력하신 키 값이 서로 일치하지 않습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                textBoxConKey.Focus(); return;
            }

            if (textBoxPassword.Text == "")
            {
                MessageBox.Show("비밀번호를 입력해 주세요.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                textBoxPassword.Focus(); return;
            }

            if (textBoxPassword.Text != textBoxConPassword.Text)
            {
                MessageBox.Show("입력하신 비밀번호가 서로 일치하지 않습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                textBoxConPassword.Focus(); return;
            }
            #endregion

            AES256 AES = new AES256();
            string hashString = null; byte[] encryptedBytes = null;

            // 암호화 기본 설정
            AES.KeyString = textBoxKey.Text;
            AES.SaltBytes = CommonData.EncryptSalt;

            // 폴더 생성
            Directory.CreateDirectory(Path.Combine(Application.StartupPath, CommonData.Folder));

            // 비밀번호 암호화
            hashString     = Convert.ToBase64String(SHA512.Create().ComputeHash(Encoding.UTF8.GetBytes(CommonData.HashSalt + textBoxPassword.Text)));
            encryptedBytes = AES.EncryptByte(Encoding.UTF8.GetBytes(hashString + textBoxPassword.Text));

            // 정보 저장
            File.WriteAllBytes(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.PasswordFile), encryptedBytes);

            // 성공 메세지
            MessageBox.Show("성공적으로 비밀번호를 생성하였습니다. \n프로그램을 다시 실행해 주세요.", "알림", MessageBoxButtons.OK, MessageBoxIcon.Information);
            Application.Exit();
        }
Exemple #6
0
        // 파일에서 정보 로드
        public void LoadFile()
        {
            if (File.Exists(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.DataFile)))
            {
                using (MemoryStream MS = new MemoryStream())
                {
                    using (StreamReader SR = new StreamReader(MS, Encoding.UTF8))
                    {
                        try
                        {
                            AES256 AES = new AES256();
                            byte[] decryptedBytes = null; string[] arrItems = new string[5];

                            decryptedBytes = AES.DecryptByte(File.ReadAllBytes(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.DataFile)));
                            MS.Write(decryptedBytes, 0, decryptedBytes.Length); MS.Position = 0;

                            // 리스트뷰 데이터 입력 준비
                            mainForm.listViewMain.BeginUpdate();

                            // 리스트뷰에 데이터 추가
                            while (!SR.EndOfStream)
                            {
                                for (int i = 0; i < 5; i++)
                                {
                                    arrItems[i] = SR.ReadLine();
                                }

                                Add(arrItems);
                            }

                            // 리스트뷰 데이터 입력 완료
                            mainForm.listViewMain.EndUpdate();
                        }
                        catch
                        {
                            Application.Exit();
                        }
                    }
                }
            }
        }
Exemple #7
0
        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 buttonAuth_Click(object sender, EventArgs e)
        {
            AES256 AES = new AES256();
            string hashString = null; byte[] encryptedBytes = null;

            // 비밀번호 암호화
            hashString     = Convert.ToBase64String(SHA512.Create().ComputeHash(Encoding.UTF8.GetBytes(CommonData.HashSalt + textBoxAuthPassword.Text)));
            encryptedBytes = AES.EncryptByte(Encoding.UTF8.GetBytes(hashString + textBoxAuthPassword.Text));

            // 정보 로드 및 배열 비교 준비
            byte[] loadData         = File.ReadAllBytes(Path.Combine(Application.StartupPath, CommonData.Folder, CommonData.PasswordFile));
            IStructuralEquatable SE = loadData;

            // 배열 서로 비교
            if (SE.Equals(encryptedBytes, StructuralComparisons.StructuralEqualityComparer))
            {
                MessageBox.Show("정상적으로 인증되었습니다.", "알림", MessageBoxButtons.OK, MessageBoxIcon.Information);
                groupBoxAuth.Enabled = false; groupBoxChange.Enabled = true;
            }
            else
            {
                MessageBox.Show("로그인에 실패하였습니다.", "오류", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        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();
            }
        }