Beispiel #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>");
            }
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //save
            if (tbS1.Text.Trim() == "")
            {
                return;
            }
            if (tbP1.Text.Trim() == "")
            {
                return;
            }
            if (tbL1.Text.Trim() == "")
            {
                return;
            }
            if (tbW1.Text.Trim() == "")
            {
                return;
            }
            if (tbS2.Text.Trim() == "")
            {
                return;
            }
            if (tbP2.Text.Trim() == "")
            {
                return;
            }
            if (tbL2.Text.Trim() == "")
            {
                return;
            }
            if (tbW2.Text.Trim() == "")
            {
                return;
            }
            if (tbSite.Text.Trim() == "")
            {
                return;
            }

            SQLLiteconnect sql = new SQLLiteconnect("db.db3");

            sql.SQLTransact("Delete from MyMail");
            List <string> ListParam = new List <string>();

            ListParam.Add(DesClass.Encrypt(tbS1.Text.Trim(), pass));
            ListParam.Add(DesClass.Encrypt(tbS2.Text.Trim(), pass));
            ListParam.Add(DesClass.Encrypt(tbW1.Text.Trim(), pass));
            ListParam.Add(DesClass.Encrypt(tbW2.Text.Trim(), pass));
            ListParam.Add(DesClass.Encrypt(tbL1.Text.ToLower().Trim(), pass));
            ListParam.Add(DesClass.Encrypt(tbL2.Text.Trim(), pass));
            ListParam.Add(tbP1.Text.Trim());
            ListParam.Add(tbP2.Text.Trim());
            sql.SQLTransactParam("INSERT INTO MyMail (S1,S2,W1,W2,L1,L2,P1,P2,id) VALUES(?,?,?,?,?,?,?,?,0)", ListParam);

            sql.SQLTransact("UPDATE PubKeySite SET name='" + tbSite.Text.Trim() + "'");
            MessageBox.Show("OK");
            this.Close();
        }
Beispiel #3
0
        private void button1_Click(object sender, EventArgs e)//load header mail
        {
            if (date1.Value > date2.Value)
            {
                MessageBox.Show("ERROR period.");
                return;
            }
            sb = new StringBuilder();
            DataTable      tbl = new DataTable();
            SQLLiteconnect sql = new SQLLiteconnect("db.db3");

            tbl = sql.SelectTable("select S1,S2,W1,W2,L1,L2,P1,P2 from MyMail");

            if (tbl.Rows[0][0].ToString().Trim().Length > 0)
            {
                S1 = DesClass.Decrypt(tbl.Rows[0][0].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][1].ToString().Trim().Length > 0)
            {
                S2 = DesClass.Decrypt(tbl.Rows[0][1].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][2].ToString().Trim().Length > 0)
            {
                W1 = DesClass.Decrypt(tbl.Rows[0][2].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][3].ToString().Trim().Length > 0)
            {
                W2 = DesClass.Decrypt(tbl.Rows[0][3].ToString().Trim(), pass);
            }


            if (tbl.Rows[0][4].ToString().Trim().Length > 0)
            {
                L1 = DesClass.Decrypt(tbl.Rows[0][4].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][5].ToString().Trim().Length > 0)
            {
                L2 = DesClass.Decrypt(tbl.Rows[0][5].ToString().Trim(), pass);
            }

            P1 = tbl.Rows[0][6].ToString();
            P2 = tbl.Rows[0][7].ToString();

            if (S1 == "")
            {
                MessageBox.Show("Options failed"); return;
            }
            Loadheader();
        }
Beispiel #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            String contact = Microsoft.VisualBasic.Interaction.InputBox("Input Contact", "Contact", "", this.Location.X + 100, this.Location.Y + 100);

            if (contact.Trim() == "")
            {
                return;
            }
            DataTable      tbl = new DataTable();
            SQLLiteconnect sql = new SQLLiteconnect("db.db3");

            sql.SQLTransact("INSERT INTO MyContacts (name, publickey) VALUES('" + DesClass.Encrypt(contact.ToLower().Trim(), pass) + "','')");
            ListContact();
        }
Beispiel #5
0
        public FormOptions(String Pass)
        {
            InitializeComponent();
            pass = Pass;
            DataTable      tbl = new DataTable();
            SQLLiteconnect sql = new SQLLiteconnect("db.db3");

            tbl = sql.SelectTable("select S1,S2,W1,W2,L1,L2,P1,P2 from MyMail");

            if (tbl.Rows[0][0].ToString().Trim().Length > 0)
            {
                tbS1.Text = DesClass.Decrypt(tbl.Rows[0][0].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][1].ToString().Trim().Length > 0)
            {
                tbS2.Text = DesClass.Decrypt(tbl.Rows[0][1].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][2].ToString().Trim().Length > 0)
            {
                tbW1.Text = DesClass.Decrypt(tbl.Rows[0][2].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][3].ToString().Trim().Length > 0)
            {
                tbW2.Text = DesClass.Decrypt(tbl.Rows[0][3].ToString().Trim(), pass);
            }


            if (tbl.Rows[0][4].ToString().Trim().Length > 0)
            {
                tbL1.Text = DesClass.Decrypt(tbl.Rows[0][4].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][5].ToString().Trim().Length > 0)
            {
                tbL2.Text = DesClass.Decrypt(tbl.Rows[0][5].ToString().Trim(), pass);
            }

            tbP1.Text = tbl.Rows[0][6].ToString();
            tbP2.Text = tbl.Rows[0][7].ToString();

            tbl = sql.SelectTable("select name from PubKeySite");
            if (tbl.Rows[0][0].ToString().Trim().Length > 0)
            {
                tbSite.Text = tbl.Rows[0][0].ToString().Trim();
            }
        }
Beispiel #6
0
        private void button3_Click(object sender, EventArgs e)
        {
            //save to base
            if (tbK1.Text.Trim() == "")
            {
                return;
            }
            if (tbK2.Text.Trim() == "")
            {
                return;
            }

            SQLLiteconnect sql = new SQLLiteconnect("db.db3");

            sql.SQLTransact("UPDATE MyTable SET pubkey='" + DesClass.Encrypt(tbK1.Text.Trim(), pass) + "', privkey='" + DesClass.Encrypt(tbK2.Text.Trim(), pass) + "'");
            MessageBox.Show("OK");
        }
Beispiel #7
0
        public RSAForm(String Pass)
        {
            InitializeComponent(); pass = Pass;
            DataTable      tbl = new DataTable();
            SQLLiteconnect sql = new SQLLiteconnect("db.db3");

            tbl = sql.SelectTable("select pubkey, privkey from MyTable");

            if (tbl.Rows[0][0].ToString().Trim().Length > 0)
            {
                tbK1.Text = DesClass.Decrypt(tbl.Rows[0][0].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][1].ToString().Trim().Length > 0)
            {
                tbK2.Text = DesClass.Decrypt(tbl.Rows[0][1].ToString().Trim(), pass);
            }
        }
Beispiel #8
0
        public void ListContact()
        {
            listBox1.Items.Clear();
            DataTable      tbl = new DataTable();
            SQLLiteconnect sql = new SQLLiteconnect("db.db3");

            tbl = sql.SelectTable("select name, publickey from MyContacts");
            if (tbl.Rows.Count != 0)
            {
                for (int i = 0; i < tbl.Rows.Count; i++)
                {
                    ContactClass CC = new ContactClass();
                    CC.Mail                = DesClass.Decrypt(tbl.Rows[i][0].ToString().Trim(), pass);
                    CC.Publickey           = DesClass.Decrypt(tbl.Rows[i][1].ToString().Trim(), pass);
                    listBox1.DisplayMember = "Mail";
                    listBox1.Items.Add(CC);
                }
            }
        }
Beispiel #9
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");
            }
        }
Beispiel #10
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (tbW3.Text.Trim().Length < 6)
            {
                MessageBox.Show("Error. Min length = 6"); return;
            }
            if (MessageBox.Show("Change your password?", "Change your password", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                if (tbS1.Text.Trim() == "")
                {
                    return;
                }
                if (tbP1.Text.Trim() == "")
                {
                    return;
                }
                if (tbL1.Text.Trim() == "")
                {
                    return;
                }
                if (tbW1.Text.Trim() == "")
                {
                    return;
                }
                if (tbS2.Text.Trim() == "")
                {
                    return;
                }
                if (tbP2.Text.Trim() == "")
                {
                    return;
                }
                if (tbL2.Text.Trim() == "")
                {
                    return;
                }
                if (tbW2.Text.Trim() == "")
                {
                    return;
                }
                if (tbSite.Text.Trim() == "")
                {
                    return;
                }

                SQLLiteconnect sql       = new SQLLiteconnect("db.db3");
                DataTable      tbl       = new DataTable();
                List <string>  ListParam = new List <string>();

                tbl = sql.SelectTable("select name, publickey from MyContacts");
                if (tbl.Rows.Count != 0)
                {
                    sql.SQLTransact("Delete from MyContacts");
                    for (int i = 0; i < tbl.Rows.Count; i++)
                    {
                        String pubkeycontact = DesClass.Decrypt(tbl.Rows[i][1].ToString().Trim(), pass);
                        String namecontact   = DesClass.Decrypt(tbl.Rows[i][0].ToString().Trim(), pass);
                        sql.SQLTransact("INSERT INTO MyContacts (name, publickey) VALUES('" + DesClass.Encrypt(namecontact, tbW3.Text.Trim()) + "','" + DesClass.Encrypt(pubkeycontact, tbW3.Text.Trim()) + "')");
                    }
                }

                String def = sha256(tbW3.Text.Trim());

                tbl = sql.SelectTable("select pubkey,privkey from MyTable");
                String pubkey  = DesClass.Decrypt(tbl.Rows[0][0].ToString().Trim(), pass);
                String privkey = DesClass.Decrypt(tbl.Rows[0][1].ToString().Trim(), pass);
                sql.SQLTransact("Delete from MyTable");

                sql.SQLTransactParam("INSERT INTO MyTable (pass,pubkey,privkey) VALUES('" + def + "','" + DesClass.Encrypt(pubkey, tbW3.Text.Trim()) + "','" + DesClass.Encrypt(privkey, tbW3.Text.Trim()) + "')", ListParam);

                pass = tbW3.Text.Trim();
                ListParam.Clear();
                sql.SQLTransact("Delete from MyMail");

                ListParam.Add(DesClass.Encrypt(tbS1.Text.Trim(), pass));
                ListParam.Add(DesClass.Encrypt(tbS2.Text.Trim(), pass));
                ListParam.Add(DesClass.Encrypt(tbW1.Text.Trim(), pass));
                ListParam.Add(DesClass.Encrypt(tbW2.Text.Trim(), pass));
                ListParam.Add(DesClass.Encrypt(tbL1.Text.ToLower().Trim(), pass));
                ListParam.Add(DesClass.Encrypt(tbL2.Text.Trim(), pass));
                ListParam.Add(tbP1.Text.Trim());
                ListParam.Add(tbP2.Text.Trim());
                sql.SQLTransactParam("INSERT INTO MyMail (S1,S2,W1,W2,L1,L2,P1,P2,id) VALUES(?,?,?,?,?,?,?,?,0)", ListParam);


                MessageBox.Show("Reopen application");
                Application.Exit();
            }
        }
Beispiel #11
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();
        }
Beispiel #12
0
        private void button1_Click(object sender, EventArgs e)
        {
            //send
            if (comboBox1.SelectedIndex == -1)
            {
                return;
            }
            ContactClass CC = (ContactClass)comboBox1.Items[comboBox1.SelectedIndex];

            if (CC.Publickey.Trim() == "")
            {
                MessageBox.Show("No publickey"); return;
            }


            DataTable      tbl = new DataTable();
            SQLLiteconnect sql = new SQLLiteconnect("db.db3");

            tbl = sql.SelectTable("select S1,S2,W1,W2,L1,L2,P1,P2 from MyMail");

            String S2 = "";
            String L1 = "";
            String L2 = "";
            String W2 = "";
            String P2 = "";

            if (tbl.Rows[0][1].ToString().Trim().Length > 0)
            {
                S2 = DesClass.Decrypt(tbl.Rows[0][1].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][3].ToString().Trim().Length > 0)
            {
                W2 = DesClass.Decrypt(tbl.Rows[0][3].ToString().Trim(), pass);
            }


            if (tbl.Rows[0][4].ToString().Trim().Length > 0)
            {
                L1 = DesClass.Decrypt(tbl.Rows[0][4].ToString().Trim(), pass);
            }

            if (tbl.Rows[0][5].ToString().Trim().Length > 0)
            {
                L2 = DesClass.Decrypt(tbl.Rows[0][5].ToString().Trim(), pass);
            }

            P2 = tbl.Rows[0][7].ToString();

            if (S2 == "")
            {
                MessageBox.Show("Options failed"); return;
            }
            if (W2 == "")
            {
                MessageBox.Show("Options failed"); return;
            }
            if (P2 == "")
            {
                MessageBox.Show("Options failed"); return;
            }
            if (L1 == "")
            {
                MessageBox.Show("Options failed"); return;
            }


            var    fromAddress  = new MailAddress(L1.Trim(), "");
            string fromPassword = W2.Trim();
            var    toAddress    = new MailAddress(CC.Mail.Trim(), "");

            const string subject = "Cryptomail";

            richTextBox1.Text += "**************************************************************************************";
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < richTextBox1.Text.Length; i++)
            {
                sb.Append(DesClass.RSAEnc(richTextBox1.Text.Substring(0, 40), CC.Publickey));
                richTextBox1.Text = richTextBox1.Text.Remove(0, 40);
                if (richTextBox1.Text.Length <= 40)
                {
                    sb.Append(DesClass.RSAEnc(richTextBox1.Text, CC.Publickey));
                    break;
                }
            }

            var smtp = new SmtpClient
            {
                Host                  = S2.Trim(),
                Port                  = Convert.ToInt32(P2.Trim()),
                EnableSsl             = true,
                DeliveryMethod        = SmtpDeliveryMethod.Network,
                UseDefaultCredentials = false,
                Credentials           = new System.Net.NetworkCredential(fromAddress.Address, fromPassword)
            };

            using (var message = new MailMessage(fromAddress, toAddress)
            {
                Subject = subject,
                Body = sb.ToString(),
            })

            {
                // message.Headers.Add("X-Message-Flag", "Flagged");
                smtp.Send(message);
            }
            richTextBox1.Text = "";
            MessageBox.Show("OK");
        }
Beispiel #13
0
        private void contextMenuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (listBox1.SelectedIndex == -1)
            {
                return;
            }

            if (e.ClickedItem == contextMenuStrip1.Items[0])//read body mail
            {
                //answer
                if (listBox1.SelectedIndex == -1)
                {
                    return;
                }
                DataTable      tbl = new DataTable();
                SQLLiteconnect sql = new SQLLiteconnect("db.db3");
                tbl = sql.SelectTable("select privkey from MyTable");

                if (tbl.Rows[0][0].ToString().Trim().Length > 0)
                {
                    privKey = DesClass.Decrypt(tbl.Rows[0][0].ToString().Trim(), pass);
                }

                int          k  = 0;
                MailObjClass MO = (MailObjClass)listBox1.Items[listBox1.SelectedIndex];
                richTextBox1.Clear();
                richTextBox1.Text += "From: " + MO.Mailfrom + "\r\n";
                richTextBox1.Text += "Date: " + MO.Datesend + "\r\n";
                richTextBox1.Text += "\r\n";
                t  = true;
                sb = new StringBuilder();
                ReadCryptoMail(Convert.ToInt32(MO.Nummail));
                String bodymail2 = "";
                String bodymail  = sb.ToString();
                //richTextBox2.Text = sb.ToString();
                while (bodymail.IndexOf("=") > 0)
                {
                    k = bodymail.IndexOf("==");
                    if (k <= 0)
                    {
                        k = bodymail.IndexOf("=");
                        if (k > 0)
                        {
                            bodymail2 = bodymail.Substring(0, k + 1);
                            bodymail  = bodymail.Remove(0, k + 1);
                            if (bodymail2.Length > 3)
                            {
                                //  MessageBox.Show(Parts[i]);
                                String part = bodymail2.Replace(".", "");
                                if (part.IndexOf("3D") == 0)
                                {
                                    part = part.Remove(0, 2);
                                }
                                richTextBox1.Text += DesClass.RSADec(part, privKey);
                            }
                        }
                    }
                    else
                    {
                        bodymail2 = bodymail.Substring(0, k + 2);
                        bodymail  = bodymail.Remove(0, k + 2);
                        if (bodymail2.Length > 3)
                        {
                            //  MessageBox.Show(Parts[i]);
                            String part = bodymail2.Replace(".", "");
                            if (part.IndexOf("3D") == 0)
                            {
                                part = part.Remove(0, 2);
                            }
                            richTextBox1.Text += DesClass.RSADec(part, privKey);
                        }
                    }
                }

                //----------------bodymail;
                SendMailForm SMF = new SendMailForm(pass, MO.Mailfrom, MO.Datesend + "\r\n" + richTextBox1.Text);

                SMF.ShowDialog();
            }
        }