Ejemplo n.º 1
0
        private static byte[] DecryptV6(KMSV6Request kmsRequest)
        {
            byte[] iv        = kmsRequest.Salt;
            byte[] encrypted = kmsRequest.Salt.Concat(kmsRequest.EncryptedRequest).ToArray();

            return(AesCrypt.DecryptAesCbc(encrypted, AesCrypt.V6RoundKeys, iv));
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 3
0
        private void checkBox1_CheckedChanged(object sender, EventArgs e)
        {
            try
            {
                string dir = "FolderLockData";

                if (File.Exists("data\\" + dir + "\\data.ls"))
                {
                    var    streamr      = new StreamReader("data\\" + dir + "\\data.ls");
                    string encsavedpath = streamr.ReadLine();
                    string decsavedpath = AesCrypt.Decrypt(encsavedpath);
                    checkBox1.Text = decsavedpath;
                    path           = checkBox1.Text;
                    streamr.Close();

                    if (path != null)
                    {
                        textBox1.Text = path;
                        button2.Select();
                    }
                }
                else
                {
                    MessageBox.Show("Path Information is Missing");
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 4
0
        private void btn_Login_Click(object sender, RoutedEventArgs e)
        {
            if (txt_pass.Password == null || txt_user.Text == null)
            {
                MessageBox.Show("Please enter username or password");
            }
            else
            {
                string usr = txt_user.Text;

                if (!Directory.Exists("Data\\" + usr))
                {
                    tb_Logfail.Visibility = Visibility.Visible;
                }
                else
                {
                    var sr = new StreamReader("Data\\" + usr + "\\Data.ls");

                    string ecUser = sr.ReadLine();
                    string ecPass = sr.ReadLine();
                    sr.Close();

                    string dcUser = AesCrypt.Decrypt(ecUser);
                    string dcPass = AesCrypt.Decrypt(ecPass);

                    if (dcUser == txt_user.Text && dcPass == txt_pass.Password)
                    {
                        MessageBox.Show("Welcome " + txt_user.Text);
                    }
                }
            }
        }
Ejemplo n.º 5
0
        public void Registration(UserModel userModel)
        {
            UserEntity user = Database.Repository <UserEntity>().GetByLogin(userModel.Login);

            if (user != null)
            {
                throw new Exception("User already exist");
            }
            // Encrypt the password
            string encryptedPassword = new AesCrypt().EncryptAes(userModel.Password);

            try
            {
                Database.Repository <UserEntity>().Insert(new UserEntity
                {
                    Login    = userModel.Login,
                    Password = encryptedPassword,
                    Email    = new EmailEntity {
                        EmailAdress = userModel.Email
                    },
                    RoleId = userModel.RoleId
                });
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            Database.SaveChanges();
            IdRole = userModel.RoleId;
        }
Ejemplo n.º 6
0
        private void button10_Click(object sender, EventArgs e)//decrypt aes
        {
            //string text = testtextbox.Text;
            string decrypted = AesCrypt.Decrypt(testtextbox.Text);

            testtextbox.Text = decrypted;
        }
Ejemplo n.º 7
0
        private void button9_Click(object sender, EventArgs e) //encyrpt aes
        {
            //string text = testtextbox.Text;
            string encrypted = AesCrypt.Encrypt(testbox.Text);

            testtextbox.Text = encrypted;
        }
Ejemplo n.º 8
0
        private List <CredentialGroup> GetCredentials(byte[] key, byte[] iv)
        {
            ICrypt aesCrypt  = new AesCrypt(key, iv);
            ICrypt byteShift = new ByteShifter(4190, "vmqup4amöovcb86mnoöbsaen");
            ICredentialsStore <ICollection <CredentialGroup> > store = new CredentialFileStore("D6qA5QN31w.dat", new[] { aesCrypt, byteShift });

            return(store.Load().ToList());
        }
Ejemplo n.º 9
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");
        }
Ejemplo n.º 10
0
        private void CreatePasswordManagerInstance(byte[] aesKey, byte[] aesIV)
        {
            ICrypt aesCrypt  = new AesCrypt(aesKey, aesIV);
            ICrypt byteShift = new ByteShifter(4190, "vmqup4amöovcb86mnoöbsaen");
            ICredentialsStore <ICollection <CredentialGroup> > store = new CredentialFileStore(_storeFile, new [] { aesCrypt, byteShift });

            _manager = new PasswordSafe(store);
            ((PasswordSafe)_manager).OnCommandExecuted += MainWindow_OnCommandExecuted;
        }
Ejemplo n.º 11
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();
        }
 private void ButtonOK_Click(object sender, RoutedEventArgs e)
 {
     if (!TextBox.Text.Equals("Введите имя...") && !TextBox.Text.Equals(string.Empty))
     {
         player.Name = TextBox.Text;
         bool addRecords = true;
         bool rewrite    = false;
         foreach (Record item in records)
         {
             if (string.Compare(item.Name, player.Name, true) == 0)
             {
                 if (item.Score < player.Score)
                 {
                     item.Score = player.Score;
                     rewrite    = true;
                 }
                 addRecords = false;
                 break;
             }
         }
         if (addRecords)
         {
             records.Add(player);
             rewrite = true;
         }
         if (rewrite)
         {
             try
             {
                 if (File.Exists("records.bin"))
                 {
                     FileAttributes fileAttributes = File.GetAttributes("records.bin");
                     if (fileAttributes.HasFlag(FileAttributes.ReadOnly))
                     {
                         File.SetAttributes("records.bin", fileAttributes & ~FileAttributes.ReadOnly);
                     }
                 }
                 byte[] bytes = AesCrypt.EncryptStringToBytes(string.Join <Record>("%", records.ToArray()), Encoding.ASCII.GetBytes("zxcvqwerasdfqazx"), Encoding.ASCII.GetBytes("qazxcvbnmlpoiuyt"));
                 using (FileStream fileStream = File.Create("records.bin"))
                 {
                     fileStream.Write(bytes, 0, bytes.Length);
                 }
                 File.SetAttributes("records.bin", File.GetAttributes("records.bin") | FileAttributes.ReadOnly);
             }
             catch (Exception exception)
             {
                 Hide();
                 MainWindow.ShowError(exception.Message);
             }
         }
         Close();
     }
 }
Ejemplo n.º 13
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!");
            }
        }
Ejemplo n.º 14
0
        public async Task SetSessionAsync(string acessToken)
        {
            var authRequest = new AuthRequest(acessToken);
            var session     = await userProvider.GetSessionAsync(UserId);

            var aes = new AesCrypt();

            var stateContainer = StateContainer.GetStateContainer();

            string cryptedSession = aes.Crypt(stateContainer.sessionStateService.StrongKey, session.SessionId);

            await authRequest.MakeRequestAsync(ConfigurationManager.AppSettings.Get("devUrl") + Urls.SetServerSessionUrl + cryptedSession, HttpMethod.Get, null);
        }
Ejemplo n.º 15
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.");
            }
        }
Ejemplo n.º 16
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;
            }
        }
Ejemplo n.º 17
0
        private void button2_Click(object sender, EventArgs e)
        {
            string TakenKey = CryptKey.Text;
            string TakenIV  = CryptIV.Text;

            if (TakenKey.Length != 32 && TakenIV.Length != 16)
            {
                MessageBox.Show("Invalid key entry. Key must be 32 character");
            }
            else
            {
                AesCrypt.setKey(TakenKey);
                AesCrypt.setIV(TakenIV);
            }
        }
Ejemplo n.º 18
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();
                }
            }
        }
Ejemplo n.º 19
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();
            }
        }
Ejemplo n.º 20
0
        public void Login(UserModel userModel)
        {
            UserEntity user = Database.Repository <UserEntity>().GetByLogin(userModel.Login);

            if (user == null)
            {
                throw new Exception("User not found");
            }

            string encryptedPassword = new AesCrypt().EncryptAes(userModel.Password);

            // Compare password in database and user paswword
            if (user.Password != encryptedPassword)
            {
                throw new Exception("Password is wrong");
            }
            IdRole = user.RoleId;
        }
Ejemplo n.º 21
0
        public string getUsrName()
        {
            string dir   = user;
            string error = "USER NOT FOUND !";

            if (!Directory.Exists("data\\" + dir))
            {
                return(error);
            }
            else
            {
                var    sr4            = new StreamReader("data\\" + dir + "\\mail.ls");
                string cryptedMailUsr = sr4.ReadLine();
                sr4.Close();
                string decryptedMailUsr = AesCrypt.Decrypt(cryptedMailUsr);
                return(decryptedMailUsr);
            }
        }
Ejemplo n.º 22
0
        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                try
                {
                    if (textBox1.Text == "")
                    {
                        MessageBox.Show("Password is Empty");
                        textBox1.Clear();
                    }
                    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)
                        {
                            Code form = new Code();
                            form.Show();
                            this.Hide();
                        }
                        else
                        {
                            MessageBox.Show("Password Not Set!");
                            textBox1.Clear();
                        }
                    }
                }

                catch (Exception)
                {
                    MessageBox.Show("Password is Incorrect!");
                    textBox1.Clear();
                }
            }
        }
Ejemplo n.º 23
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;
            }
        }
Ejemplo n.º 24
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 + "از قبل موجود است ");
                }
            }
        }
 private string ReadData(string fileName)
 {
     try
     {
         using (FileStream fileStream = File.OpenRead(fileName))
         {
             byte[] buffer = new byte[fileStream.Length];
             if (fileStream.Read(buffer, 0, buffer.Length) > 0)
             {
                 return(AesCrypt.DecryptStringFromBytes(buffer, Encoding.ASCII.GetBytes("zxcvqwerasdfqazx"), Encoding.ASCII.GetBytes("qazxcvbnmlpoiuyt")));
             }
             else
             {
                 throw new Exception();
             }
         }
     }
     catch (Exception)
     {
         return(string.Empty);
     }
 }
Ejemplo n.º 26
0
        private static void Main(string[] args)
        {
            Parser.Default.ParseArguments <Options>(args).WithParsed(o =>
            {
                if (!File.Exists(o.FileName))
                {
                    Console.WriteLine(Resources.The_input_file_does_not_exist, o.FileName);
                    Environment.ExitCode = 1;
                    return;
                }

                if (o.Encrypt)
                {
                    var crypt = new AesCrypt();
                    crypt.EncryptFile(o.FileName, o.OutputFile, o.Password);
                }
                else if (o.Decrypt)
                {
                    var crypt = new AesCrypt();
                    crypt.DecryptFile(o.FileName, o.OutputFile, o.Password);
                }
            });
        }
Ejemplo n.º 27
0
        public void ChangePasswordByEmail(UserModel userModel)
        {
            string newPassword          = string.Empty;
            string encryptedNewPassword = string.Empty;

            UserEntity user = Database.Repository <UserEntity>().GetByLogin(userModel.Login);

            if (user == null)
            {
                throw new Exception("User not found");
            }
            // Generate uniqe password
            do
            {
                newPassword          = new GenerateNewPassword().Generate();
                encryptedNewPassword = new AesCrypt().EncryptAes(newPassword);
            }while (newPassword == user.Password);


            user.Password = encryptedNewPassword;
            Database.Repository <UserEntity>().Update(user);
            Database.SaveChanges();

            // Email data
            string fromAdressTitle = "Email from Bohdan Zaiats";
            string toAddress       = user.Email.EmailAdress;
            string subject         = "Generating new pasword";
            string bodyContent     = $"Your New password: {newPassword}";

            SendEmail(new EmailModel
            {
                FromAdressTitle = fromAdressTitle,
                ToAddress       = toAddress,
                Subject         = subject,
                BodyContent     = bodyContent
            });
        }
Ejemplo n.º 28
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;
            }
        }
Ejemplo n.º 29
0
        public MainWindow()
        {
            AutoUpdater.RunUpdateAsAdmin = true;
            AutoUpdater.Start("http://162.217.248.211/etes/Updater.xml");

            InitializeComponent();
            AppWindow = this;
            Notification.CreateNotify();
            Scheduler sc = new Scheduler();

            sc.Start();


            if (File.Exists("data\\data.ls"))
            {
                var sr = new StreamReader("data\\data.ls");

                string encusr  = sr.ReadLine();
                string encpass = sr.ReadLine();
                sr.Close();

                decusr  = AesCrypt.Decrypt(encusr);
                decpass = AesCrypt.Decrypt(encpass);

                textUsername.Text    = decusr;
                textPassword.Text    = decpass;
                passwordBox.Password = decpass;
            }
            else
            {
                MessageBox.Show("Ensure you fill out the login and password details and Apply.");
                Visibility = Visibility.Visible;
            }

            if (!File.Exists("Settings.ini"))
            {
                //Create new Settings.ini file
                var MyIni = new IniFile("Settings.ini");

                //Set default values for days of the week
                MyIni.Write("Saturday", "", "Week");
                MyIni.Write("Sunday", "", "Week");
                MyIni.Write("Monday", "7.50", "Week");
                MyIni.Write("Tuesday", "7.50", "Week");
                MyIni.Write("Wednesday", "7.50", "Week");
                MyIni.Write("Thursday", "7.50", "Week");
                MyIni.Write("Friday", "7.50", "Week");
                MyIni.Write("WorkOrder", "1010 REGULAR HOURS", "WorkOrder");
                MyIni.Write("Wait Time", "15", "Wait Time");
                MyIni.Write("Browser", "System.Windows.Controls.ComboBoxItem: Chrome", "Browser Choice");
                MyIni.Write("Security", "System.Windows.Controls.ComboBoxItem: VIP App (PC)", "Security Choice");
                MyIni.Write("ManualSubmit", "False", "Submit");
                MyIni.Write("Reminded", "False", "Reminders"); //sets notifyicon to ignore or send the info message about closing from the notification area.
                MyIni.Write("Applied", "False", "Check");      //checks that user has applied their data before starting browser
                MyIni.Write("SalesForce", "False", "Check");   //sets salesforce autologin option at setting.ini creation (off by default)
                MyIni.Write("CloseBrowser", "False", "Check"); //sets whether to close the browser after updating the timesheet or not.  (off by default)


                //Set variables with Settings.ini values
                //string[] settingday = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
                //TextBox[] textboxes = { textMon, textTue, textWed, textThur, textFri, textSat, textSun };
                System.Windows.Controls.TextBox[] textboxes = { textSat, textSun, textMon, textTue, textWed, textThur, textFri };
                for (int i = 0; i < settingday.Length; i++)
                {
                    textboxes[i].Text = MyIni.Read(settingday[i], "Week");
                }
                textWaittime.Text = (MyIni.Read("Wait Time", "Wait Time"));

                var browserchoice = MyIni.Read("Browser", "Browser Choice");
                if (browserchoice == "System.Windows.Controls.ComboBoxItem: Chrome")
                {
                    comboBrowser.SelectedIndex = 0;
                }
                else
                {
                    comboBrowser.SelectedIndex = 1;
                }

                var securitychoice = MyIni.Read("Security", "Security Choice");
                if (securitychoice == "System.Windows.Controls.ComboBoxItem: VIP App (PC)")
                {
                    comboSecurity.SelectedIndex = 0;
                }
                else
                {
                    comboSecurity.SelectedIndex = 1;
                }

                //Check if the Submit on Friday checkbox is checked or not and apply the correct check against the check object
                fridaycheck = MyIni.Read("ManualSubmit", "Submit");
                if (fridaycheck == "True")
                {
                    fridayCheckBox.IsChecked = true;
                }
                else
                {
                    fridayCheckBox.IsChecked = false;
                }

                //Check if the Close Browser checkbox is checked or not and apply the correct check against the check object
                browserclose = MyIni.Read("CloseBrowser", "Check");
                if (browserclose == "True")
                {
                    ChkCloseAfterUpdate.IsChecked = true;
                }
                else
                {
                    ChkCloseAfterUpdate.IsChecked = false;
                }

                //Read the apply check into the variable so that the Start button can run.  This is required so the user cant start it without applying their username and pass.
                var appliedcheck = MyIni.Read("Applied", "Check");

                //Check if we need a wait time box, Firefox needs it, Chrome doesnt
                if (comboBrowser.SelectedIndex == 1)
                {
                    textBWait.Visibility    = Visibility.Visible;
                    textWaittime.Visibility = Visibility.Visible;
                    textBlock8.Visibility   = Visibility.Visible;
                    textWaittime.Text       = (MyIni.Read("Wait Time", "Wait Time"));
                }
                else
                {
                    textBWait.Visibility    = Visibility.Hidden;
                    textWaittime.Visibility = Visibility.Hidden;
                    textBlock8.Visibility   = Visibility.Hidden;
                }
                //Read False into appliedcheck to ensure user cant start the program without applying their config.
                appliedcheck = MyIni.Read("Applied", "Check");
            }
            else
            {
                //Read Settings.ini
                var MyIni = new IniFile("Settings.ini");

                //string[] settingday = new string[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
                //TextBox[] textboxes = { textMon, textTue, textWed, textThur, textFri, textSat, textSun };
                System.Windows.Controls.TextBox[] textboxes = { textSat, textSun, textMon, textTue, textWed, textThur, textFri };
                for (int i = 0; i < settingday.Length; i++)
                {
                    textboxes[i].Text = MyIni.Read(settingday[i], "Week");
                }

                browserchoice = MyIni.Read("Browser", "Browser Choice");
                if (browserchoice == "System.Windows.Controls.ComboBoxItem: Chrome")
                {
                    comboBrowser.SelectedIndex = 0;
                }
                else
                {
                    comboBrowser.SelectedIndex = 1;
                }

                securitychoice = MyIni.Read("Security", "Security Choice");
                if (securitychoice == "System.Windows.Controls.ComboBoxItem: VIP App (PC)")
                {
                    comboSecurity.SelectedIndex = 0;
                }
                else
                {
                    comboSecurity.SelectedIndex = 1;
                }

                var fridaycheck = MyIni.Read("ManualSubmit", "Submit");
                if (fridaycheck == "True")
                {
                    fridayCheckBox.IsChecked = true;
                }
                else
                {
                    fridayCheckBox.IsChecked = false;
                }

                //Check if the Close Browser checkbox is checked or not and apply the correct check against the check object
                var browserclose = MyIni.Read("CloseBrowser", "Check");
                if (browserclose == "True")
                {
                    ChkCloseAfterUpdate.IsChecked = true;
                }
                else
                {
                    ChkCloseAfterUpdate.IsChecked = false;
                }

                //Check if we need a wait time box, Firefox needs it, Chrome doesnt
                if (comboBrowser.SelectedIndex == 1)
                {
                    textBWait.Visibility    = Visibility.Visible;
                    textWaittime.Visibility = Visibility.Visible;
                    textBlock8.Visibility   = Visibility.Visible;
                    textWaittime.Text       = (MyIni.Read("Wait Time", "Wait Time"));
                }
                else
                {
                    textBWait.Visibility    = Visibility.Hidden;
                    textWaittime.Visibility = Visibility.Hidden;
                    textBlock8.Visibility   = Visibility.Hidden;
                }
                //Read the apply check into the variable so that the Start button can run.  This is required so the user cant start it without applying their username and pass.
                var appliedcheck = MyIni.Read("Applied", "Check");
                //Read the Settings.ini file to see if we need to set the checkbox true or false.
                if (MyIni.Read("SalesForce", "Check") == "True")
                {
                    ChkSalesForce.IsChecked = true;
                    //If the checkbox for salesforce is checked, run the salesforce automation schedule.The ?? false is because IsChecked is an interdeminable bool, so it can be true, false, or null.The ?? tells it, if its null then just set it false.
                    //Scheduler sf = new Scheduler();
                    //sf.SFStart();
                }
                else
                {
                    ChkSalesForce.IsChecked = false;
                }
            }
        }
Ejemplo n.º 30
0
        public async Task MakeSessionAsync(string acessToken, string refreshToken = null)
        {
            var rsa = new RsaService();
            var aes = new AesCrypt();

            var rsaPair = rsa.GenerateKeys();

            var strongKeyRequest = new
            {
                publicKey = rsaPair.publicKey
            };

            var authRequest = new AuthRequest(acessToken);

            string strongKeyJsonRequest    = JsonConvert.SerializeObject(strongKeyRequest);
            var    strongKeyRequestMessage = authRequest.BuildRequestMessage(ConfigurationManager.AppSettings.Get("devUrl") + Urls.GetStrongKeyUrl, HttpMethod.Post, strongKeyJsonRequest);

            var strongKeyResponseMessage = await authRequest.httpClient.SendAsync(strongKeyRequestMessage);

            if (strongKeyResponseMessage.StatusCode == HttpStatusCode.NotFound)
            {
                var firstSessionRequestModel = new CreateMessangerSessionRequest()
                {
                    PublicKey = rsaPair.publicKey
                };

                string jsonRequest = JsonConvert.SerializeObject(firstSessionRequestModel);

                var firstSessionResponse = await authRequest.GetStringFromHttpResultAsync(ConfigurationManager.AppSettings.Get("devUrl") + Urls.CreateFirstSessionUrl, HttpMethod.Post, jsonRequest);

                var response = JsonConvert.DeserializeObject <CreateFirstMessangerSessionResponse>(firstSessionResponse);

                string decryptedAesKey = rsa.Decrypt(rsaPair.privateKey, response.CryptedAes);

                byte[] decryptedAesKeyBuffer = decryptedAesKey.FromUrlSafeBase64();

                await userProvider.CreateStrongKeyAsync(UserId, decryptedAesKeyBuffer);

                string newToken = await tokenService.MakeAuthTokenAsync(UserId, true);

                authRequest = new AuthRequest(newToken);

                rsaPair = rsa.GenerateKeys();

                string cryptedPublicKey    = aes.Crypt(decryptedAesKeyBuffer.ToUrlSafeBase64(), rsaPair.publicKey);
                var    sessionRequestModel = new CreateMessangerSessionRequest()
                {
                    PublicKey = cryptedPublicKey
                };

                jsonRequest = JsonConvert.SerializeObject(sessionRequestModel);

                var httpRequest     = authRequest.BuildRequestMessage(ConfigurationManager.AppSettings.Get("devUrl") + Urls.CreateSessionUrl, HttpMethod.Post, jsonRequest);
                var sessionResponse = await authRequest.httpClient.SendAsync(httpRequest);

                sessionResponse.EnsureSuccessStatusCode();

                var    session = JsonConvert.DeserializeObject <CreateMessangerSessionResponse>(await sessionResponse.Content.ReadAsStringAsync());
                string decryptedServerPublicKey = aes.Decrypt(decryptedAesKey, session.ServerPublicKey);
                string decryptedSessionId       = aes.Decrypt(decryptedAesKey, session.SessionId);

                await userProvider.CreateSessionAsync(new Session()
                {
                    ClientPrivateKey = rsaPair.privateKey,
                    ServerPublicKey  = decryptedServerPublicKey,
                    ClientPublicKey  = rsaPair.publicKey,
                    UserId           = UserId,
                    SessionId        = decryptedSessionId
                });
            }
            else if (!string.IsNullOrEmpty(refreshToken) && strongKeyResponseMessage.StatusCode == HttpStatusCode.OK)
            {
                var strongKeyResponse = JsonConvert.DeserializeObject <GetStrongKeyResponse>(
                    await strongKeyResponseMessage.Content.ReadAsStringAsync()
                    );

                var decryptedStrongKey = rsa.Decrypt(rsaPair.privateKey, strongKeyResponse.StrongKey);
                await userProvider.CreateStrongKeyAsync(UserId, decryptedStrongKey.FromUrlSafeBase64());

                rsaPair = rsa.GenerateKeys();
                var cryptedPublicKey = aes.Crypt(decryptedStrongKey, rsaPair.publicKey);

                var sessionRequest = new CreateMessangerSessionRequest()
                {
                    PublicKey = cryptedPublicKey
                };

                string jsonSessionRequest = JsonConvert.SerializeObject(sessionRequest);
                var    sessionResponse    = await authRequest.MakeRequestAsync <CreateMessangerSessionResponse>(ConfigurationManager.AppSettings.Get("devUrl") + Urls.CreateSessionUrl, HttpMethod.Post, jsonSessionRequest);

                string decryptedPublicKey = aes.Decrypt(decryptedStrongKey, sessionResponse.ServerPublicKey);
                string decryptedSessionId = aes.Decrypt(decryptedStrongKey, sessionResponse.SessionId);

                await userProvider.CreateSessionAsync(new Session()
                {
                    ClientPrivateKey = rsaPair.privateKey,
                    ClientPublicKey  = rsaPair.publicKey,
                    ServerPublicKey  = decryptedPublicKey,
                    UserId           = UserId,
                    SessionId        = decryptedSessionId
                });
            }
        }