예제 #1
0
        private void txtPass_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)Keys.Enter)
            {
                HideAll();

                e.Handled = true;

                if (!File.Exists(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CPass/pass.set")))
                {
                    string plaintext = txtPass.Text;

                    string encryptedstring = "";
                    string decryptedstring = "";

                    encryptedstring = StringCipher.Encrypt(plaintext, new NetworkCredential("", SecString).Password);
                    decryptedstring = StringCipher.Decrypt(encryptedstring, new NetworkCredential("", SecString).Password);

                    string pathPass = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CPass/pass.key");
                    string pathInfo = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CPass/info.enc");

                    Directory.CreateDirectory(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CPass"));

                    var fileStream1 = File.Create(pathPass);
                    fileStream1.Close();
                    var fileStream2 = File.Create(pathInfo);
                    fileStream2.Close();

                    TextWriter tw = new StreamWriter(pathPass);
                    tw.WriteLine(encryptedstring);
                    tw.Close();

                    try
                    {
                        File.Encrypt(pathPass);
                        File.Encrypt(pathInfo);
                    }
                    catch { }

                    var fileStream3 = File.Create(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CPass/pass.set"));
                    fileStream3.Close();

                    iconTick.Visible   = true;
                    pnlContent.Visible = true;
                    pnlContent.Hide();

                    BunifuTransition transition = new BunifuTransition();
                    transition.ShowSync(pnlContent, true, BunifuAnimatorNS.Animation.Transparent);
                }
                else
                {
                    string encryptedstring = "";
                    string decryptedstring = "";

                    encryptedstring = File.ReadAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CPass/pass.key"));
                    decryptedstring = StringCipher.Decrypt(encryptedstring, new NetworkCredential("", SecString).Password);

                    if (txtPass.Text == decryptedstring)
                    {
                        iconTick.Visible   = true;
                        pnlContent.Visible = true;
                        pnlContent.Hide();

                        using (StreamReader r = new StreamReader(File.Open(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CPass/info.enc"), FileMode.Open)))
                        {
                            string line;
                            while ((line = r.ReadLine()) != null)
                            {
                                lstInfo.Items.Add(StringCipher.Decrypt(line, new NetworkCredential("", SecString).Password));
                            }
                        }

                        BunifuTransition transition = new BunifuTransition();
                        transition.ShowSync(pnlContent, true, BunifuAnimatorNS.Animation.Transparent);
                    }
                    else
                    {
                        flash            = 0;
                        tmrFlash.Enabled = true;
                    }
                }
            }
        }