Exemplo n.º 1
0
        private void SaveAndEncrypt()
        {
            StringBuilder sb = new StringBuilder();

            foreach (Object o in lstInfo.Items)
            {
                sb.AppendLine(StringCipher.Encrypt(o.ToString(), new NetworkCredential("", SecString).Password));
            }

            System.IO.File.WriteAllText(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "CPass/info.enc"), sb.ToString());
        }
Exemplo n.º 2
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")))
                {
                    //first start
                    string plaintext       = txtPass.Text;                                  //user's pass
                    string passPhrase      = new NetworkCredential("", SecString).Password; //pass to encrypt
                    string encryptedstring = StringCipher.Encrypt(plaintext, passPhrase);   //encrypted pass

                    SavePassword(encryptedstring);                                          //create folder and write encrypted pass there

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

                    BunifuTransition transition = new BunifuTransition();
                    transition.ShowSync(pnlContent, true, BunifuAnimatorNS.Animation.Transparent);
                }
                else
                {
                    if (txtPass.Text == GetDecryptedPassword())
                    {
                        iconTick.Visible   = true;
                        pnlContent.Visible = true;
                        pnlContent.Hide();

                        //TODO: May be serialization?
                        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;
                    }
                }
            }
        }
Exemplo n.º 3
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;
                    }
                }
            }
        }