Esempio n. 1
0
 public PasswordGeek()
 {
     cr = new Crypography();
     d  = new Ts_Tree();
     ob = new cipher();
     //    cnt = new Class1();
     count = 0;
     InitializeComponent();
     arr     = new char[50];
     arr[0]  = ' ';
     arr[1]  = ',';
     arr[2]  = '-';
     arr[3]  = ';';
     arr[4]  = '.';
     arr[5]  = '\'';
     arr[6]  = '\"';
     arr[7]  = '?';
     arr[8]  = '=';
     arr[9]  = '!';
     arr[10] = '/';
     arr[11] = ':';
     arr[12] = '&';
     arr[13] = '*';
     arr[14] = '%';
     arr[15] = '(';
     arr[16] = '@';
     arr[17] = ')';
     arr[18] = '#';
     arr[19] = '_';
     arr[20] = '^';
     arr[21] = '`';
     arr[22] = '|';
     arr[21] = '[';
     arr[22] = ']';
     arr[23] = '\\';
     arr[24] = '<';
     arr[25] = '>';
     arr[26] = '~';
     arr[27] = '0';
     arr[28] = '1';
     arr[29] = '2';
     arr[30] = '3';
     arr[31] = '4';
     arr[32] = '5';
     arr[33] = '6';
     arr[34] = '7';
     arr[35] = '8';
     arr[36] = '9';
 }
Esempio n. 2
0
        private void store_Click(object sender, EventArgs e)
        {
            try
            {
                string s1, s2;
                label4.Visible = true;
                s1             = id.Text;
                s2             = pwd.Text;
                if (s1 == "" || s2 == "")
                {
                    MessageBox.Show("Incorrect format. Empty values are not allowed!");
                    return;
                }
                string final = s1 + "%DELIMITER&" + s2;
                //decrypt the privatekey.xml
                Stream sm    = new FileStream("privatekey.xml", FileMode.Open);
                byte[] e_pvt = new byte[(int)sm.Length + 1];
                sm.Read(e_pvt, 0, (int)sm.Length);
                sm.Close();
                char[] cp_pk = new char[e_pvt.Length + 1];
                //convert byte array-e_pvt to char array and decrypt
                i = 0;
                while (i < e_pvt.Length)
                {
                    cp_pk[i] = Convert.ToChar(e_pvt[i]);
                    i++;
                }
                encrypt_double ed    = new encrypt_double();
                char[]         pt_pk = ed.decrypt(cp_pk, master_password.ToCharArray());
                //convert pt_pk to byte array and write it
                byte[] towrite = new byte[pt_pk.Length + 1];
                i = 0;
                while (i < pt_pk.Length)
                {
                    towrite[i] = Convert.ToByte(pt_pk[i]);
                    i++;
                }
                Stream sm1 = new FileStream("privatekey.xml", FileMode.Create);
                sm1.Write(towrite, 0, towrite.Length);
                sm1.Close();



                //code to encrypt and serialize the objects
                cr = new Crypography();
                string cipher = cr.crypt(final);
                if (cipher.CompareTo("Illegal Values") != 0)
                {
                    //code to deserialize the cipher class1
                    Stream          stream     = File.Open("string", FileMode.Open);
                    BinaryFormatter bformatter = new BinaryFormatter();
                    ob = (cipher)bformatter.Deserialize(stream);
                    stream.Close();
                    ob.assign(cipher);
                    //serialize the cipher object
                    Stream          streamc     = new FileStream("string", FileMode.Create);
                    BinaryFormatter bformatterc = new BinaryFormatter();
                    bformatterc.Serialize(streamc, ob);
                    streamc.Close();
                    id.Text  = "";
                    pwd.Text = "";
                }
                else
                {
                    MessageBox.Show("Illegal Values. Click 'Retrieve Passwords' to retrieve your old values.");
                }
                //again encrypt privatekey.xml
                Stream sma = new FileStream("privatekey.xml", FileMode.Open);
                byte[] pvt = new byte[(int)sma.Length + 1];
                sma.Read(pvt, 0, (int)sma.Length);
                sma.Close();
                char[] plain_pka = new char[pvt.Length + 1];
                //convert byte array-pvt to char array and encrypt
                i = 0;
                while (i < pvt.Length)
                {
                    plain_pka[i] = Convert.ToChar(pvt[i]);
                    i++;
                }
                encrypt_double eda       = new encrypt_double();
                char[]         cipher_pk = ed.encrypt(plain_pka, master_password.ToCharArray());
                //convert cipher_pk to byte array and write it
                byte[] towritea = new byte[cipher_pk.Length + 1];
                i = 0;
                while (i < cipher_pk.Length)
                {
                    towritea[i] = Convert.ToByte(cipher_pk[i]);
                    i++;
                }
                Stream sm1a = new FileStream("privatekey.xml", FileMode.Create);
                sm1a.Write(towritea, 0, towritea.Length);
                sm1a.Close();
                Stream sss = new FileStream("success", FileMode.Create);
                sss.Close();
            }
            catch (Exception ed)
            {
                MessageBox.Show("An error occured while storing the passwords");
            }
        }