Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //sync
            if (comboBox1.SelectedIndex == -1)
            {
                return;
            }
            ContactClass CC = (ContactClass)comboBox1.Items[comboBox1.SelectedIndex];

            if (CC.Publickey.Trim() == "")
            {
                if (MessageBox.Show("No publickey. Sync pubkey?", "Sync pubkey", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    String result = DesClass.Decode(ServerAPIClass.ReadPubKey(DesClass.Encode(CC.Mail.ToLower().Trim())));
                    if (result.Trim() == "")
                    {
                        MessageBox.Show("ERROR");
                    }
                    else
                    {
                        String         pubkey = "<RSAKeyValue><Modulus>" + result + "</Exponent></RSAKeyValue>";
                        DataTable      tbl    = new DataTable();
                        SQLLiteconnect sql    = new SQLLiteconnect("db.db3");
                        sql.SQLTransact("UPDATE MyContacts SET publickey='" + DesClass.Encrypt(pubkey, pass) + "' where name='" + DesClass.Encrypt(CC.Mail.ToLower().Trim(), pass) + "'");
                        MessageBox.Show("OK");
                        LoadContacts();
                    }
                }
            }
            else
            {
                MessageBox.Show("<RSAKeyValue><Modulus>" + CC.Publickey.Trim() + "</Exponent></RSAKeyValue>");
            }
        }
Exemplo n.º 2
0
        private void button2_Click(object sender, EventArgs e)
        {
            //send to server
            if (tbK1.Text.Trim() == "")
            {
                return;
            }
            DataTable      tbl = new DataTable();
            SQLLiteconnect sql = new SQLLiteconnect("db.db3");

            tbl = sql.SelectTable("select L1 from MyMail");
            String mail = "";

            if (tbl.Rows[0][0].ToString().Trim().Length > 0)
            {
                mail = DesClass.Decrypt(tbl.Rows[0][0].ToString().Trim(), pass);
            }
            if (mail == "")
            {
                return;
            }
            String pubkey = tbK1.Text.Trim().Replace("<RSAKeyValue><Modulus>", "");

            pubkey = pubkey.Trim().Replace("</Exponent></RSAKeyValue>", "");
            String result = ServerAPIClass.SendPubKey(DesClass.Encode(mail), DesClass.Encode(pubkey));

            //  tbK2.Text = "<RSAKeyValue><Modulus>" + DesClass.Decode(ServerAPIClass.ReadPubKey(DesClass.Encode(mail), "http://localhost:8080")) + "</Exponent></RSAKeyValue>";
            if (result.Trim() == "OK")
            {
                MessageBox.Show("OK");
            }
            else
            {
                MessageBox.Show("ERROR");
            }
        }
Exemplo n.º 3
0
        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (listBox1.SelectedIndex == -1)
            {
                return;
            }
            if (e.ClickedItem == contextMenuStrip1.Items[0])
            {
                //edit
                ContactClass CC      = (ContactClass)listBox1.Items[listBox1.SelectedIndex];
                String       contact = Microsoft.VisualBasic.Interaction.InputBox("Input Contact", "Contact", CC.Mail, this.Location.X + 100, this.Location.Y + 100);
                if (contact.Trim() == "")
                {
                    return;
                }
                DataTable      tbl = new DataTable();
                SQLLiteconnect sql = new SQLLiteconnect("db.db3");
                sql.SQLTransact("UPDATE MyContacts SET name='" + DesClass.Encrypt(contact.ToLower().Trim(), pass) + "' where name='" + DesClass.Encrypt(CC.Mail.ToLower().Trim(), pass) + "'");
            }
            if (e.ClickedItem == contextMenuStrip1.Items[1])
            {
                //del
                if (MessageBox.Show("Delete the selected contact?", "Delete contact", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    ContactClass   CC  = (ContactClass)listBox1.Items[listBox1.SelectedIndex];
                    DataTable      tbl = new DataTable();
                    SQLLiteconnect sql = new SQLLiteconnect("db.db3");
                    sql.SQLTransact("Delete from MyContacts where name='" + DesClass.Encrypt(CC.Mail.ToLower().Trim(), pass) + "'");
                }
            }
            if (e.ClickedItem == contextMenuStrip1.Items[4])
            {
                //sync
                ContactClass CC = (ContactClass)listBox1.Items[listBox1.SelectedIndex];

                String result = DesClass.Decode(ServerAPIClass.ReadPubKey(DesClass.Encode(CC.Mail.ToLower().Trim())));
                if (result.Trim() == "")
                {
                    MessageBox.Show("ERROR");
                }
                else
                {
                    String pubkey = "<RSAKeyValue><Modulus>" + result + "</Exponent></RSAKeyValue>";

                    //MessageBox.Show(pubkey);
                    DataTable      tbl = new DataTable();
                    SQLLiteconnect sql = new SQLLiteconnect("db.db3");
                    sql.SQLTransact("UPDATE MyContacts SET publickey='" + DesClass.Encrypt(pubkey, pass) + "' where name='" + DesClass.Encrypt(CC.Mail.ToLower().Trim(), pass) + "'");
                    MessageBox.Show("OK");
                }
            }

            if (e.ClickedItem == contextMenuStrip1.Items[2])
            {
                //create cryptomail
                ContactClass CC  = (ContactClass)listBox1.Items[listBox1.SelectedIndex];
                SendMailForm SMF = new SendMailForm(pass, CC.Mail.Trim(), "");
                SMF.ShowDialog();
            }

            if (e.ClickedItem == contextMenuStrip1.Items[3])
            {
                //show publickey
                ContactClass CC = (ContactClass)listBox1.Items[listBox1.SelectedIndex];
                if (CC.Publickey.Trim() == "")
                {
                    MessageBox.Show("No publickey");
                }
                else
                {
                    MessageBox.Show("<RSAKeyValue><Modulus>" + CC.Publickey.Trim() + "</Exponent></RSAKeyValue>");
                }
            }

            ListContact();
        }