Пример #1
0
        public void AddEncryption(string FileName1)
        {
            try
            {
                if (path != null)
                {
                    string dir = "FileEncryptData";
                    Directory.CreateDirectory("data\\" + dir);
                    var streamw = new StreamWriter("data\\" + dir + "\\data.ls");

                    string dc = AesCrypt.Encrypt(textBoxSelect_Path.Text);
                    streamw.WriteLine(dc);
                    streamw.Close();
                    try
                    {
                        File.Encrypt(FileName1);
                        MessageBox.Show("File has been Encrypted!", "Congratulations!", MessageBoxButtons.OK);
                        checkBox2.Visible = true;
                    }
                    catch (Exception ex)
                    {
                        throw ex;
                    }
                }
                else
                {
                    MessageBox.Show("Select Path First");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #2
0
        private void button9_Click(object sender, EventArgs e) //encyrpt aes
        {
            //string text = testtextbox.Text;
            string encrypted = AesCrypt.Encrypt(testbox.Text);

            testtextbox.Text = encrypted;
        }
Пример #3
0
        private void btn_Apply_Click(object sender, RoutedEventArgs e)
        {
            if (textUsername.Text.Length < 3 || passwordBox.Password.Length < 5)
            {
                MessageBox.Show("Username or Password is invalid");
            }
            else
            {
                Directory.CreateDirectory("data\\");

                var sw = new StreamWriter("data\\data.ls");

                var encusr  = AesCrypt.Encrypt(textUsername.Text);
                var encpass = AesCrypt.Encrypt(passwordBox.Password);

                sw.WriteLine(encusr);
                sw.WriteLine(encpass);
                sw.Close();

                MessageBox.Show(String.Format("User {0} configuration was successfully saved.", textUsername.Text));

                var sr = new StreamReader("data\\data.ls");

                var r_encusr  = sr.ReadLine();
                var r_encpass = sr.ReadLine();
                sr.Close();

                decusr  = AesCrypt.Decrypt(r_encusr);
                decpass = AesCrypt.Decrypt(r_encpass);

                textUsername.Text    = decusr;
                textPassword.Text    = decpass;
                passwordBox.Password = decpass;
            }

            var MyIni = new IniFile("Settings.ini");

            System.Windows.Controls.TextBox[] textboxes = { textSat, textSun, textMon, textTue, textWed, textThur, textFri };
            for (int i = 0; i < settingday.Length; i++)
            {
                MyIni.Write(settingday[i], textboxes[i].Text, "Week");
            }
            if (comboBrowser.SelectedIndex == 1)
            {
                MyIni.Write("Wait Time", textWaittime.Text, "Wait Time");
            }

            MyIni.Write("Browser", comboBrowser.SelectedItem.ToString(), "Browser Choice");
            MyIni.Write("Security", comboSecurity.SelectedItem.ToString(), "Security Choice");
            MyIni.Write("ManualSubmit", fridayCheckBox.IsChecked.ToString(), "Submit");
            MyIni.Write("CloseBrowser", ChkCloseAfterUpdate.IsChecked.ToString(), "Check");
            securitychoice = MyIni.Read("Security", "Security Choice");
            browserchoice  = MyIni.Read("Browser", "Browser Choice");
            browserclose   = MyIni.Read("CloseBrowser", "Check");
            //Once apply is clicked write true to the settings.ini file and then read it into our public string of appliedcheck so that when start checks it will allow it through
            MyIni.Write("Applied", "True", "Check");
            appliedcheck = MyIni.Read("Applied", "Check");
        }
Пример #4
0
        public void TestAesEncryptDecrypt_256_Cbc()
        {
            foreach (string item in data)
            {
                var encrypted = aes256Cbc.Encrypt(item);
                var decrypted = aes256Cbc.Decrypt(encrypted);

                Assert.AreEqual(decrypted, item);
            }
        }
Пример #5
0
        public void TestAesEncryptDecrypt_192_Cfb()
        {
            foreach (string item in data)
            {
                var encrypted = aes192Cfb.Encrypt(item);
                var decrypted = aes192Cfb.Decrypt(encrypted);

                Assert.AreEqual(decrypted, item);
            }
        }
Пример #6
0
        private void ProductRegistry_Load(object sender, EventArgs e)
        {
            ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT SerialNumber FROM Win32_BaseBoard");

            foreach (ManagementObject MySerial in searcher.Get())
            {
                string bserial = MySerial.GetPropertyValue("SerialNumber").ToString();
                txtcopycode.Text = AesCrypt.Encrypt(bserial);
            }
            ProductRegistry pf = new ProductRegistry();
        }
Пример #7
0
        private void button1_Click(object sender, EventArgs e)//sender
        {
            string appSign = "UrfaDiyarbakir";


            if (listBox1.SelectedIndex >= 0)
            {
                char[] charsToTrim = { ' ', '"' };
                int    index       = listBox1.SelectedIndex;
                var    dateTime    = DateTime.Now;
                string mailfrom    = logformobj.getUsrName();
                string mailpass    = logformobj.getUsrPass();
                try
                {
                    string encryptedAESkey = friends[index, 0].Trim(charsToTrim);
                    string decryptedAESkey = RSAobj.Decrypt(encryptedAESkey);
                    string mailTo          = friends[index, 2].Trim(charsToTrim);
                    var    post            = new MailMessage(mailfrom, mailTo);
                    string MailSign        = textBox1.Text + "\n" + dateTime;
                    string cryptedMailSign = RSAobj.SignData(MailSign);
                    post.Subject = AesCrypt.EncryptParam(textBox2.Text, decryptedAESkey);
                    post.Body    = AesCrypt.Encrypt(appSign) + "---AppSign---" + AesCrypt.Encrypt(EncryptedMailApp.LoginForm.user) + "---Username---" + AesCrypt.EncryptParam(textBox1.Text + "\n" + dateTime, decryptedAESkey) + "---Body---" + cryptedMailSign + "---Sign---";
                    ;

                    using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
                    {
                        smtp.Credentials = new NetworkCredential(mailfrom, mailpass);
                        smtp.EnableSsl   = true;
                        if (!string.IsNullOrEmpty(textBox3.Text))
                        {
                            EncryptedMailApp.CryptoStuff.EncryptFile(password, textBox3.Text, textBox3.Text + "crp");
                            Attachment data = new Attachment(textBox3.Text + "crp");
                            post.Attachments.Add(data);
                            smtp.Send(post);
                            MessageBox.Show("Email Sent With Attachment");
                        }
                        else
                        {
                            smtp.Send(post);
                            MessageBox.Show("Email Sent");
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("ERROR");
                }
            }
            else
            {
                MessageBox.Show("There is no selected friend!");
            }
        }
Пример #8
0
        private void SendMail()
        {
            string mailfrom = logform.getUsrName();
            string mailpass = logform.getUsrPass();
            string msg;


            try
            {
                var dateTime = DateTime.Now;
                var messag   = new MailMessage(mailfrom, mailTo.Text);
                messag.Subject = subject.Text;

                if (checkBox1.Checked == true && checkBox2.Checked == true)
                {
                    msg         = AesCrypt.Encrypt(message.Text + "\n" + dateTime);
                    messag.Body = msg;
                }

                if (checkBox1.Checked == true && checkBox2.Checked == false)
                {
                    msg         = AesCrypt.Encrypt(message.Text + "\n" + dateTime);
                    messag.Body = msg;
                }
                if (checkBox1.Checked == false && checkBox2.Checked == true)
                {
                    msg         = message.Text + "\n" + dateTime;
                    messag.Body = msg;
                }
                if (checkBox1.Checked == false && checkBox2.Checked == false)
                {
                    msg         = message.Text + "\n" + dateTime;
                    messag.Body = msg;
                }


                using (SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587))
                {
                    smtp.Credentials = new NetworkCredential(mailfrom, mailpass);
                    smtp.EnableSsl   = true;
                    Attachment data = new Attachment(textBox3.Text);
                    messag.Attachments.Add(data);
                    smtp.Send(messag);
                    MessageBox.Show("Email Sent");
                }
            }
            catch
            {
                MessageBox.Show("Please check your mail address and password.");
            }
        }
Пример #9
0
        public void SetAccess()
        {
            try
            {
                if (path != null)
                {
                    DirectoryInfo myDirectoryInfo = new DirectoryInfo(path);

                    string dir = "FileLockData";
                    Directory.CreateDirectory("data\\" + dir);
                    var streamw = new StreamWriter("data\\" + dir + "\\data.ls");

                    string dc = AesCrypt.Encrypt(textBoxSelect_Path.Text);
                    streamw.WriteLine(dc);
                    streamw.Close();


                    var sid = new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null);

                    DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();

                    myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(sid, FileSystemRights.Read, AccessControlType.Deny));
                    var everyid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
                    var usersid = new SecurityIdentifier(WellKnownSidType.BuiltinUsersSid, null);

                    var accsid   = new SecurityIdentifier(WellKnownSidType.BuiltinAccountOperatorsSid, null);
                    var adnissid = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);

                    myDirectorySecurity.RemoveAccessRuleAll(new FileSystemAccessRule(everyid, FileSystemRights.Read, AccessControlType.Allow));
                    myDirectorySecurity.RemoveAccessRuleAll(new FileSystemAccessRule(usersid, FileSystemRights.Read, AccessControlType.Allow));

                    myDirectorySecurity.RemoveAccessRuleAll(new FileSystemAccessRule(accsid, FileSystemRights.Read, AccessControlType.Allow));
                    myDirectorySecurity.RemoveAccessRuleAll(new FileSystemAccessRule(adnissid, FileSystemRights.Read, AccessControlType.Allow));
                    myDirectoryInfo.SetAccessControl(myDirectorySecurity);

                    MessageBox.Show("File has been Locked!", "Congratulations!", MessageBoxButtons.OK);

                    checkBox1.Visible = true;
                }

                else
                {
                    MessageBox.Show("Select Path First");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Пример #10
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (Pass_textBox.Text == "")
            {
                MessageBox.Show("Password is Empty");
            }
            else
            {
                string dir     = "Userdata";
                var    streamr = new StreamReader("data\\" + dir + "\\data.ls");


                string encpass = streamr.ReadLine();
                streamr.Close();


                string decpass = AesCrypt.Decrypt(encpass);

                if (decpass == textBox1.Text)
                {
                    if (Pass_textBox.Text.Length < 4)
                    {
                        MessageBox.Show("Password is Invaled or too short!");
                    }
                    else
                    {
                        string dir1 = "Userdata";
                        Directory.CreateDirectory("data\\" + dir1);

                        var streamw = new StreamWriter("data\\" + dir1 + "\\data.ls");

                        string w_encpass = AesCrypt.Encrypt(Pass_textBox.Text);

                        streamw.WriteLine(w_encpass);
                        streamw.Close();

                        MessageBox.Show("Password Successfully Changed.");
                        Pass_textBox.Clear();
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Password Not Matched!");
                    textBox1.Clear();
                }
            }
        }
Пример #11
0
        private void registerbtn_Click(object sender, EventArgs e)
        {
            if (usrname.Text.Length < 4 && usrpass.Text.Length < 4)
            {
                MessageBox.Show("Username or Password is invalid.");
            }
            else
            {
                RSACrypt RSAobj = RSACrypt.getInstance();
                RSAobj.createKey();
                string dir = usrname.Text;
                Directory.CreateDirectory("data\\" + dir);
                var sw = new StreamWriter("data\\" + dir + "\\data.ls");

                string encusr  = AesCrypt.Encrypt(usrname.Text);
                string encpass = AesCrypt.Encrypt(usrpass.Text);
                sw.WriteLine(encusr);
                sw.WriteLine(encpass);
                sw.Close();

                var    sw2       = new StreamWriter("data\\" + dir + "\\PublicKey.ls");
                string PublicKey = RSAobj.RSApublicKey;
                //string PublicKey = new string(RSAobj.PublicKey.Where(c => !char.IsWhiteSpace(c)).ToArray());
                sw2.WriteLine(PublicKey);
                sw2.Close();

                var sw3 = new StreamWriter("data\\" + dir + "\\PrivateKey.ls");
                //string PrivateKey = new string(RSAobj.PrivateKey.Where(c => !char.IsWhiteSpace(c)).ToArray());
                string PrivateKey = RSAobj.PrivateKey;
                sw3.WriteLine(PrivateKey);
                sw3.Close();

                var    sw4          = new StreamWriter("data\\" + dir + "\\mail.ls");
                string UserMail     = AesCrypt.Encrypt(UserMailTextBox.Text);
                string UserMailPass = AesCrypt.Encrypt(UserMailPassBox.Text);
                sw4.WriteLine(UserMail);
                sw4.WriteLine(UserMailPass);
                sw4.Close();

                RgClient.Set(usrname.Text + "/publicKey", PublicKey);
                RgClient.Set(usrname.Text + "/mail", UserMailTextBox.Text);


                MessageBox.Show("Registration successful.", usrname.Text);
                this.Close();
            }
        }
Пример #12
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string dir = "UserCode";
                Directory.CreateDirectory("data\\" + dir);

                var streamw = new StreamWriter("data\\" + dir + "\\data.ls");


                string Code1  = AesCrypt.Encrypt(textBox2.Text);
                string Code2  = AesCrypt.Encrypt(textBox3.Text);
                string Code3  = AesCrypt.Encrypt(textBox4.Text);
                string Code4  = AesCrypt.Encrypt(textBox5.Text);
                string Code5  = AesCrypt.Encrypt(textBox6.Text);
                string Code6  = AesCrypt.Encrypt(textBox7.Text);
                string Code7  = AesCrypt.Encrypt(textBox8.Text);
                string Code8  = AesCrypt.Encrypt(textBox9.Text);
                string Code9  = AesCrypt.Encrypt(textBox10.Text);
                string Code10 = AesCrypt.Encrypt(textBox11.Text);
                string Code11 = AesCrypt.Encrypt(textBox12.Text);
                string Code12 = AesCrypt.Encrypt(textBox13.Text);
                streamw.WriteLine(Code1);
                streamw.WriteLine(Code2);
                streamw.WriteLine(Code3);
                streamw.WriteLine(Code4);
                streamw.WriteLine(Code5);
                streamw.WriteLine(Code6);
                streamw.WriteLine(Code7);
                streamw.WriteLine(Code8);
                streamw.WriteLine(Code9);
                streamw.WriteLine(Code10);
                streamw.WriteLine(Code11);
                streamw.WriteLine(Code12);
                streamw.Close();

                MessageBox.Show("Code Successfully Added.");
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #13
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            if (usrTxt.Text.Length < 3 || passTxt.Text.Length < 5)
            {
                MessageBox.Show("نام کاربر یا رمز عبور اشتباه یا کوتاه است");
            }
            else
            {
                string encusr  = AesCrypt.Encrypt(usrTxt.Text);
                string encpass = AesCrypt.Encrypt(passTxt.Text);

                DataAccess.cmd = new SqlCommand("select * from Operators where Username = @username", DataAccess.con);
                DataAccess.cmd.Parameters.AddWithValue("@username", encusr);
                DataAccess.con.Open();

                DataAccess.Dataset = new DataSet();
                DataAccess.SQLDA   = new SqlDataAdapter(DataAccess.cmd);
                DataAccess.SQLDA.Fill(DataAccess.Dataset);
                DataAccess.con.Close();


                bool loginSuccessful = ((DataAccess.Dataset.Tables.Count > 0) && (DataAccess.Dataset.Tables[0].Rows.Count > 0));

                if (loginSuccessful == false)
                {
                    string AddEmployee = "Insert Into Operators(Username,Password) Values('" + encusr + "','" + encpass + "');";
                    DataAccess.con.Open();
                    DataAccess.cmd = new SqlCommand(AddEmployee, DataAccess.con);
                    DataAccess.cmd.ExecuteNonQuery();
                    DataAccess.con.Close();

                    MessageBox.Show("موفقانه ثبت شد " + usrTxt.Text + " کاربز ");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("کاربر " + usrTxt.Text + "از قبل موجود است ");
                }
            }
        }
Пример #14
0
        private void btn_Create_Click(object sender, RoutedEventArgs e)
        {
            if (txt_passReg.Password == null || txt_userReg.Text == null)
            {
                MessageBox.Show("Username or Password is too short");
            }
            else
            {
                string dir = txt_userReg.Text;
                Directory.CreateDirectory("Data\\" + dir);

                var sw = new StreamWriter("Data\\" + dir + "\\Data.ls");

                //Encrypting user data.
                string UserEnc = AesCrypt.Encrypt(txt_userReg.Text);
                string PassEnc = AesCrypt.Encrypt(txt_passReg.Password);

                sw.WriteLine(UserEnc);
                sw.WriteLine(PassEnc);
                sw.Close();

                tb_regsucc.Visibility = Visibility.Visible;
            }
        }
Пример #15
0
        private void GetMail()
        {
            string mailfrom = logform.getUsrName();
            string mailpass = logform.getUsrPass();

            try {
                Task.Run(() =>
                {
                    using (ImapClient client = new ImapClient("imap.gmail.com", 993, mailfrom, mailpass, AuthMethod.Login, true))
                    {
                        if (client.Supports("IDLE") == false)
                        {
                            MessageBox.Show("Server do not support IMAP IDLE");
                            return;
                        }
                        string cryptedAppSign = AesCrypt.Encrypt("UrfaDiyarbakir");

                        var uids  = client.Search(SearchCondition.Text(cryptedAppSign));
                        int index = 0;


                        foreach (var id in uids)
                        {
                            var m = client.GetMessage(id, FetchOptions.Normal);


                            int a = m.Body.IndexOf("---AppSign---") + "---AppSign---".Length;
                            int b = m.Body.IndexOf("---Username---");

                            int c = m.Body.IndexOf("---Username---") + "---Username---".Length;
                            int d = m.Body.IndexOf("---Body---");

                            int e = m.Body.IndexOf("---Body---") + "---Body---".Length;
                            int f = m.Body.IndexOf("---Sign---");

                            string appsign       = m.Body.Substring(0, m.Body.IndexOf("---AppSign---"));
                            string Username      = AesCrypt.Decrypt(m.Body.Substring(a, b - a));
                            string sign          = m.Body.Substring(e, f - e);
                            string encryptedBody = m.Body.Substring(c, d - c);
                            string dir           = EncryptedMailApp.LoginForm.user;


                            char[] charsToTrim  = { ' ', '"' };
                            string encryptedAES = FbClient.Get(EncryptedMailApp.LoginForm.user + "/friends/" + Username + "/aes").Body.ToString().Trim(charsToTrim);
                            string friendPublic = FbClient.Get(EncryptedMailApp.LoginForm.user + "/friends/" + Username + "/publicKey").Body.ToString().Trim(charsToTrim);
                            string aes;
                            string decryptedBody;
                            string decryptedSubject;
                            try
                            {
                                string decryptetaes = RSAobj.Decrypt(encryptedAES);
                                aes = decryptetaes;
                            }
                            catch
                            {
                                aes = null;
                                Console.WriteLine("error on decrypting aes ");
                            }
                            try
                            {
                                decryptedBody = AesCrypt.DecryptParam(encryptedBody, aes);
                            }
                            catch
                            {
                                decryptedBody = null;
                                Console.WriteLine("error on decrpting body");
                            }
                            try
                            {
                                decryptedSubject = AesCrypt.DecryptParam(m.Subject, aes);
                            }
                            catch
                            {
                                decryptedSubject = null;
                                Console.WriteLine("error on decrpting subject");
                            }
                            if (RSAobj.VerifySign(decryptedBody, sign, friendPublic) == true)
                            {
                                Console.WriteLine("match");
                                signed = true;
                            }
                            else
                            {
                                Console.WriteLine("missmatch");
                                signed = false;
                            }

                            if (messages[index, 0] == null)
                            {
                                messages[index, 0] = Username;
                                messages[index, 1] = decryptedSubject;
                                messages[index, 2] = decryptedBody;
                            }

                            listBox1.Items.Add(new ListItem {
                                Name = "From:   " + Username + "   Subject:   " + decryptedSubject, Value = index.ToString()
                            });

                            index++;

                            foreach (Attachment attachment in m.Attachments)
                            {
                                byte[] allBytes = new byte[attachment.ContentStream.Length];
                                int bytesread   = attachment.ContentStream.Read(allBytes, 0, (int)attachment.ContentStream.Length);
                                if (System.IO.Directory.Exists("data\\" + dir + "\\attachments") == false)
                                {
                                    System.IO.Directory.CreateDirectory("data\\" + dir + "\\attachments");
                                }
                                string destinationFile = "data\\" + dir + "\\attachments\\" + attachment.Name;
                                BinaryWriter writer    = new BinaryWriter(new FileStream(destinationFile, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None));
                                writer.Write(allBytes);
                                writer.Close();
                                if (attachment.Name.EndsWith("crp"))
                                {
                                    EncryptedMailApp.CryptoStuff.DecryptFile(password, destinationFile, destinationFile.Replace("crp", ""));
                                }
                                //MessageBox.Show("saved attachment at attachments, attachment count is : "+ m.Attachments.Count);
                            }
                        }

                        this.listBox1.MouseDoubleClick += new MouseEventHandler(listBox1_MouseDoubleClick);
                    }
                });
            }
            catch (InvalidCredentialsException)
            {
                MessageBox.Show("The server rejected the supplied credentials.");
            }
        }
Пример #16
0
        private void button1_Click_1(object sender, EventArgs e)
        {
            if (usrTxt.Text.Length < 3 || passTxt.Text.Length < 5)
            {
                MessageBox.Show("نام کاربر یا رمز عبور اشتباه یا کوتاه است");
            }
            else
            {
                string usrchk  = AesCrypt.Encrypt(usrTxt.Text);
                string passchk = AesCrypt.Encrypt(passTxt.Text);
                DataAccess.RunQuery("Select * From Operators where Username= '******'");
                int i = DataAccess.Dataset.Tables[0].Rows.Count;


                string dir = usrTxt.Text;


                if (i <= 0)
                {
                    MessageBox.Show(" در سیستم موجود نیست " + dir + " کاربر");
                }
                else
                {
                    DataAccess.cmd = new SqlCommand("select * from Operators where Username = @username and Password = @password", DataAccess.con);
                    DataAccess.cmd.Parameters.AddWithValue("@username", usrchk);
                    DataAccess.cmd.Parameters.AddWithValue("@password", passchk);
                    DataAccess.con.Open();

                    DataAccess.Dataset = new DataSet();
                    DataAccess.SQLDA   = new SqlDataAdapter(DataAccess.cmd);
                    DataAccess.SQLDA.Fill(DataAccess.Dataset);
                    DataAccess.con.Close();


                    bool loginSuccessful = ((DataAccess.Dataset.Tables.Count > 0) && (DataAccess.Dataset.Tables[0].Rows.Count > 0));

                    if (loginSuccessful == true)
                    {
                        decusr  = AesCrypt.Decrypt(usrchk);
                        decpass = AesCrypt.Decrypt(passchk);
                    }



                    if (decusr == usrTxt.Text && decpass == passTxt.Text)
                    {
                        DataAccess.con.Close();
                        MessageBox.Show("خوش آمدید" + " داخل سیستم " + decusr);

                        chkup = true;
                    }
                    else
                    {
                        MessageBox.Show("نام کاربر یا رمز عبور اشتباه است");
                    }
                    if (chkup == true)
                    {
                        MainForm MF = new MainForm();
                        MF.Show();
                        Login_System_Encrypted lf = new Login_System_Encrypted();
                        this.Visible = false;
                    }
                }
            }
        }