Example #1
0
 private void BtnCreate_Click(object sender, EventArgs e)
 {
     if (lblInfoMinimumChars.ForeColor == System.Drawing.Color.Green && lblnfoPIN.ForeColor == System.Drawing.Color.Green && lblInfoVerifyPIN.ForeColor == System.Drawing.Color.Green)
     {
         k   = new generate();
         key = k.gen(true, true, true, true, 25);//generate key
         NewAcc(txtUsername.Text, txtPIN.Text, key);
     }
 }
Example #2
0
 private void BtnGenerovat_Click(object sender, EventArgs e)
 {
     if (chkMalaPismena.Checked == false && chkVelkaPismena.Checked == false && chkSymboly.Checked == false && chkCisla.Checked == false)
     {
         MessageBox.Show("Chyba, zvol si něco");
     }
     else
     {
         generate pass = new generate();
         heslo        = pass.gen(chkMalaPismena.Checked, chkVelkaPismena.Checked, chkCisla.Checked, chkSymboly.Checked, delka);
         DialogResult = DialogResult.OK;
     }
 }
Example #3
0
        private void NewAcc(string name, string pin, string key)//create new acc
        {
            string       res, textToEncrypt;
            string       cryptoAccKey = null;
            string       cryptoBinKey = null;
            DialogResult dialogResult = MessageBox.Show("Jméno: " + name + Environment.NewLine + "PIN: " + pin + Environment.NewLine + "Správně?", "Ověření", MessageBoxButtons.YesNo);

            if (dialogResult == DialogResult.Yes)
            {
                string accsPath = Path.GetDirectoryName(Application.ExecutablePath) + "\\accs";
                string binPath  = Path.GetDirectoryName(Application.ExecutablePath) + "\\bin";

                if (!Directory.Exists(binPath))          // jestli existuje slozka bin
                {
                    Directory.CreateDirectory(binPath);  //vytvorit
                }
                if (!Directory.Exists(accsPath))         // jestli existuje slozka s uzivateli
                {
                    Directory.CreateDirectory(accsPath); //vytvorit
                }

                if (!File.Exists(accsPath + "\\key.xml"))//vytvori klic pro spravu uctu
                {
                    RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();

                    StreamWriter SaveKey = new StreamWriter(accsPath + "\\key.xml");
                    SaveKey.Write(cryptoAccKey = (RSA.ToXmlString(true)));
                    SaveKey.Close();
                }
                else//nebo precte pokud ma
                {
                    try
                    {
                        RSACryptoServiceProvider RSAacc = new RSACryptoServiceProvider();

                        StreamReader OpenKey = new StreamReader(accsPath + "\\key.xml");
                        cryptoAccKey = OpenKey.ReadToEnd();
                        OpenKey.Close();
                        RSAacc.FromXmlString(cryptoAccKey);
                    }
                    catch//pokud precte a bude v key.xml chyba
                    {
                        MessageBox.Show("Chyba v souboru: " + accsPath + "\\key.xml");

                        Application.OpenForms[0].Show();
                        this.Hide();
                    }
                }

                if (!File.Exists(accsPath + "\\" + name + ".dll"))//zda neexistuje soubor s takovym uctem
                {
                    res           = "";
                    textToEncrypt = name + ";" + pin + ";" + key;
                    res           = Crypter.Encrypt(textToEncrypt, cryptoAccKey);//zasifruje

                    StreamWriter strmAccWrite = new StreamWriter(accsPath + "\\" + name + ".dll");
                    strmAccWrite.Write(res);
                    strmAccWrite.Close();

                    while (true)
                    {
                        if (!Directory.Exists(binPath + "\\" + key + "\\"))         //zepta se jestli je slozka a soubor pro ulozeni dat
                        {
                            Directory.CreateDirectory(binPath + "\\" + key + "\\"); //vytvori se direktorie

                            #region ziskani klice cryptoBinKey
                            if (!File.Exists(binPath + "\\" + key + "\\" + "key.xml"))//vytvori se unikatni klic pro slozku s hesly
                            {
                                Directory.CreateDirectory(binPath + "\\" + key);
                                RSACryptoServiceProvider RSAbin = new RSACryptoServiceProvider();

                                StreamWriter SaveKey = new StreamWriter(binPath + "\\" + key + "\\" + "key.xml");
                                SaveKey.Write(cryptoBinKey = (RSAbin.ToXmlString(true)));
                                SaveKey.Close();
                            }
                            else
                            {
                                try
                                {
                                    RSACryptoServiceProvider RSAbin = new RSACryptoServiceProvider();

                                    StreamReader OpenKey = new StreamReader(binPath + "\\" + key + "\\" + "key.xml");
                                    cryptoBinKey = OpenKey.ReadToEnd();
                                    OpenKey.Close();
                                    RSAbin.FromXmlString(cryptoAccKey);
                                }
                                catch//pokud precte a bude v key.xml chyba
                                {
                                    MessageBox.Show("Chyba v souboru: " + binPath + "\\" + key + "\\" + "key.xml");

                                    Application.OpenForms[0].Show();
                                    this.Hide();
                                }
                            }
                            #endregion

                            Directory.CreateDirectory(binPath + "\\" + key + "\\" + "1");//vytvori se direktorie

                            string[] data = new string[] { " ", " ", " ", " " };
                            for (int i = 0; i < 4; i++)
                            {
                                StreamWriter strmBinWrite = new StreamWriter(binPath + "\\" + key + "\\1\\" + (i + 1).ToString() + ".dll");
                                strmBinWrite.Write(Crypter.Encrypt(data[i], cryptoBinKey));
                                strmBinWrite.Close();
                            }

                            StreamWriter strmAccWrite2 = new StreamWriter(accsPath + "\\" + name + ".dll");
                            res           = "";
                            textToEncrypt = name + ";" + pin + ";" + key;
                            res           = Crypter.Encrypt(textToEncrypt, cryptoAccKey);
                            strmAccWrite2.Write(res);
                            strmAccWrite2.Close();


                            MessageBox.Show("Účet je vytvořen :)");
                            if (Application.OpenForms[0].Name == "Form1")
                            {
                                Application.OpenForms[0].Show();
                            }
                            this.Hide();
                            break;
                        }
                        else
                        {
                            k   = new generate();
                            key = k.gen(true, true, true, true, 25);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Účet jíž existuje, vytvořte jiný");
                }
            }

            else if (dialogResult == DialogResult.No)
            {
                txtPIN.Text            = "";
                txtUsername.Text       = "";
                txtVerifyPIN.Text      = "";
                txtPIN.ForeColor       = Color.Red;
                txtVerifyPIN.ForeColor = Color.Red;
                txtUsername.ForeColor  = Color.Red;
            }
        }