Beispiel #1
0
        protected override IAsyncResult BeginExecute(AsyncCodeActivityContext context, AsyncCallback callback, object state)
        {
            authUrl     = AuthenticationUrl.Get(context);
            authMethod  = AuthenticationMethod.Get(context);
            authBrowser = AuthenticationBrowser.Get(context);
            email       = Email.Get(context);
            if (authMethod != "Manual" && email == null)
            {
                throw new ArgumentException("Email must be supplied with Automatic Authorization");
            }
            passwordInsecure = PasswordInsecure.Get(context);
            if (authMethod == "Insecure" && passwordInsecure == null)
            {
                throw new ArgumentException("Insecure Password must be supplied with Insecure Authentication");
            }
            passwordSecure = PasswordSecure.Get(context);
            if (authMethod == "Secure" && passwordSecure == null)
            {
                throw new ArgumentException("Secure Password must be supplied with Secure Authentication");
            }

            browserLoadTimeout = BrowserLoadTimeout.Get(context);
            if (browserLoadTimeout == 0)
            {
                browserLoadTimeout = BrowserLoadTimeoutDefault;
            }

            BuildDefaultAuthUrl(context);
            BuildUrlAndFilename();
            BuildAuthArguments();

            LoadFileDelegate = new Action(LoadFile);
            return(LoadFileDelegate.BeginInvoke(callback, state));
        }
Beispiel #2
0
        private void ClearKey()
        {
            if (key != null)
            {
                key.Dispose();
                key = null;
            }

            clearRecords();
        }
Beispiel #3
0
        public string decrypt(string base64str, PasswordSecure pwd = null)
        {
            if (pwd == null)
            {
                pwd = key;
            }

            var sha     = new SHA3(base64str.Length);
            var openKey = pwd.getObjectValue();
            var crypted = sha.multiDecryptLZMA(Convert.FromBase64String(base64str), openKey);

            BytesBuilder.BytesToNull(openKey);

            var result = new UTF32Encoding().GetString(crypted); //Convert.ToBase64String(crypted);

            BytesBuilder.ToNull(crypted);
            return(result);
        }
Beispiel #4
0
        public void SetPassword(string pass, string index)
        {
            using (var con = new SqlConnection(builder.ConnectionString))
                using (var com = new SqlCommand())
                {
                    com.Connection = con;
                    con.Open();

                    com.CommandText = "Update Student set Password=@Password, Salt=@Salt WHERE IndexNumber=@IndexNumber";
                    var coder          = PasswordSecure.CoderCreator();
                    var hashedPassword = SecurePassword.Create(pass, salt);
                    com.Parameters.AddWithValue("Password", hashedPassword);
                    com.Parameters.AddWithValue("Salt", coder);
                    com.Parameters.AddWithValue("IndexNumber", index);

                    var dr = com.ExecuteNonQuery();
                }
        }
Beispiel #5
0
        public string crypt(string str, PasswordSecure pwd = null)
        {
            if (pwd == null)
            {
                pwd = key;
            }

            var sha = new SHA3(str.Length);

            if (random == null)
            {
                var inits = str + DateTime.Now.ToString("r");
                var t     = new UTF32Encoding().GetBytes(inits);
                var bbi   = new BytesBuilder();
                bbi.add(t);
                bbi.add(sha.CreateInitVector(0, 64, 40));
                var init = bbi.getBytes();

                random = new SHA3.SHA3Random(init);

                bbi.clear();
                BytesBuilder.ClearString(inits);
                BytesBuilder.ToNull(init);
            }

            var bytes = new UTF32Encoding().GetBytes(str);

            var openKey = pwd.getObjectValue();
            var crypted = sha.multiCryptLZMA(bytes, openKey, null, 22, false);

            BytesBuilder.BytesToNull(openKey);
            BytesBuilder.BytesToNull(bytes);
            BytesBuilder.ClearString(str);

            return(Convert.ToBase64String(crypted));
        }
Beispiel #6
0
        private void recryptFile()
        {
            DoublePasswordForm pwdForm1, pwdForm2 = null;
            bool isSuccess = false;

            do
            {
                pwdForm1 = new DoublePasswordForm(1);
                pwdForm1.ShowDialog();

                if (pwdForm1.resultText == null)
                {
                    return;
                }

                if (pwdForm1.resultText.Length < 6)
                {
                    MessageBox.Show("Извините, но введённый текст настолько мал, что не может являться паролем", "Шифрование", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    continue;
                }

                if (pwdForm1.fromFile)
                {
                    break;
                }

                pwdForm2 = new DoublePasswordForm(2);
                pwdForm2.ShowDialog();

                if (pwdForm2.cancel)
                {
                    pwdForm1.clearResultText();
                    return;
                }

                if (!String.IsNullOrEmpty(pwdForm2.resultText) && pwdForm1.resultText != pwdForm2.resultText)
                {
                    pwdForm1.clearResultText();
                    pwdForm2.clearResultText();
                    if (MessageBox.Show("Введённые пароли не равны друг другу\r\nХотите попробовать ещё раз?", "Шифрование", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
                    {
                        return;
                    }
                }
                else
                {
                    isSuccess = true;
                }
            }while (!isSuccess);

            byte[] newKey1;
            Form1.GetKeyByPassword(pwdForm1, out newKey1, 10);
            pwdForm1.clearResultText();
            pwdForm2.clearResultText();

            var sha    = new SHA3(0);
            var newKey = new PasswordSecure(newKey1);

            foreach (var record in records)
            {
                record.Value.pwd   = crypt(decrypt(record.Value.pwd), newKey);
                record.Value.crypt = crypt(decrypt(record.Value.crypt), newKey);
            }

            ClearKey();
            key = newKey;

            recordsToFile();
        }
Beispiel #7
0
        void cnt_closedEventDecrypt(Form1.OpenFileDialogContext context, bool isOK)
        {
            if (!isOK)
            {
                return;
            }

toStart:

            DoublePasswordForm pwdForm1, pwdForm2 = null;
            bool isSuccess = false;

            do
            {
                pwdForm1 = new DoublePasswordForm(1, Path.GetFileName(context.dialog.FileName));
                pwdForm1.ShowDialog();

                if (pwdForm1.resultText == null)
                {
                    return;
                }

                if (pwdForm1.resultText.Length < 6)
                {
                    MessageBox.Show("Извините, но введённый текст настолько мал, что не может являться паролем", "Шифрование", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    continue;
                }

                if (pwdForm1.fromFile)
                {
                    break;
                }

                pwdForm2 = new DoublePasswordForm(2, Path.GetFileName(context.dialog.FileName));
                pwdForm2.ShowDialog();

                if (pwdForm2.cancel)
                {
                    pwdForm1.clearResultText();
                    return;
                }

                if (!String.IsNullOrEmpty(pwdForm2.resultText) && pwdForm1.resultText != pwdForm2.resultText)
                {
                    pwdForm1.clearResultText();
                    pwdForm2.clearResultText();
                    if (MessageBox.Show("Введённые пароли не равны друг другу\r\nХотите попробовать ещё раз?", "Шифрование", MessageBoxButtons.YesNo) != System.Windows.Forms.DialogResult.Yes)
                    {
                        return;
                    }
                }
                else
                {
                    isSuccess = true;
                }
            }while (!isSuccess);

            ClearKey();
            ClearWindow();

            byte[] key1;
            Form1.GetKeyByPassword(pwdForm1, out key1, 22);
            pwdForm1.clearResultText();
            pwdForm2.clearResultText();

            var sha = new SHA3(0);

            var fi = new FileInfo(context.dialog.FileName);

            fileName = fi.FullName;
            if (!fi.Exists)
            {
                var newBytes = sha.multiCryptLZMA(new byte[0], key1, null, 12, false, 0, SHA3.getHashCountForMultiHash() - 8);
                File.WriteAllBytes(fileName, newBytes);
            }

            try
            {
                var openFile      = File.ReadAllBytes(fileName);
                var decryptedFile = sha.multiDecryptLZMA(openFile, key1);

                if (decryptedFile == null)
                {
                    MessageBox.Show("Файл расшифровать не удалось");
                    BytesBuilder.BytesToNull(key1);
                    goto toStart;
                }

                this.key = new PasswordSecure(key1);
                var str = Encoding.UTF32.GetString(decryptedFile);

                BytesBuilder.ToNull(openFile);
                BytesBuilder.ToNull(decryptedFile);

                GetRecordsFromFile(str);
                BytesBuilder.ClearString(str);
            }
            catch (Exception e)
            {
                MessageBox.Show("Расшифрование не удалось! " + e.Message, "Расшифрование не удалось", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }

            SetTagsAndMainTags();
        }