Пример #1
0
        public static Boolean PostProcessEncryptFile(string inputFile, string outputFile, Guid GUID)
        {
            Boolean isCancelEncryptionProcess = false;

            isCancelEncryptionProcess = Securebox._PostProcessEncryptFile(inputFile, outputFile, GUID);
            return(isCancelEncryptionProcess);
        }
Пример #2
0
        private void Encrypt_Button_Click(object sender, RoutedEventArgs e)
        {
            var           _fileList                 = explorer.ViewModel.FileList.Selection.SelectedItems;
            List <string> encryptedFileNames        = new List <string>();
            Boolean       isCancelEncryptionProcess = false;

            foreach (var el in _fileList)
            {
                if (System.IO.Path.GetExtension(el.EntryModel.FullPath) == Securebox.secureboxExtension)
                {
                    //System.Windows.Forms.DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("File is already encrypted, press \"Cancel\" to skip remaining selected file(s), press \"Ok\" to continue", "File is already encrypted by Securebox", MessageBoxButtons.OKCancel);
                    //isCancelEncryptionProcess = dialogResult == System.Windows.Forms.DialogResult.Cancel;
                }
                else
                {
                    Guid g;
                    // Create and display the value of two GUIDs.
                    g = Guid.NewGuid();
                    Securebox.EncryptFile(el.EntryModel.FullPath, el.EntryModel.FullPath + ".tmp", g);
                    isCancelEncryptionProcess = Securebox.PostProcessEncryptFile(el.EntryModel.FullPath + ".tmp", el.EntryModel.FullPath + ".box", g);
                    encryptedFileNames.Add(System.IO.Path.GetFileName(el.EntryModel.FullPath));
                }

                if (isCancelEncryptionProcess)
                {
                    break;
                }
            }
            var            report = String.Join("\n", encryptedFileNames.ToArray());
            IScriptCommand cmd    = UIScriptCommands.FileListRefresh(true, UIScriptCommands.MessageBoxOK("Report", report));

            explorer.ViewModel.Commands.ExecuteAsync(cmd);
        }
Пример #3
0
 public SecureboxFileExplorer(IProfile[] profiles, IEntryModel[] rootDirs, string mask, string selectedPath = "c:\\")
 {
     InitializeComponent();
     Securebox.CenterWindowOnScreen(this);
     _profiles     = profiles;
     _rootDirs     = rootDirs;
     _filterStr    = mask;
     _selectedPath = selectedPath;
 }
Пример #4
0
        private static void _DecryptPreprocess(string inputFile)
        {
            string outputFile = inputFile + ".tmp";

            int numberOfBytes = 16;

            byte[] bytes = new byte[numberOfBytes];
            //get GUID from file
            using (var fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read))
            {
                fs.Read(bytes, 0, bytes.Length);
            }
            // var buffer2 = File.ReadAllBytes(inputFile);
            Guid   guid = new Guid(bytes);
            string GUID = guid.ToString();

            //create new file without GUID

            char[]   delimiterChars      = { '.' };
            string[] newFile             = outputFile.Split(delimiterChars);
            string   newFileFullPathName = String.Join(".", newFile.Take(newFile.Length - 2));

            using (var fs = new FileStream(inputFile, FileMode.Open, FileAccess.Read))
            {
                byte[] fullfile = new byte[fs.Length];
                int    toRead = (int)fs.Length - 1, bytesRead;
                fs.Seek(16, SeekOrigin.Begin);
                while (toRead > 0 && (bytesRead = fs.Read(fullfile, 0, toRead)) > 0)
                {
                    toRead        -= bytesRead;
                    numberOfBytes += bytesRead;
                }
                using (var newFS = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
                {
                    newFS.Write(fullfile, 0, fullfile.Length);
                }
            }
            //get IV and key from SQLite DB
            SecureboxKey el = DatabaseManagement.GetSecureboxKey(GUID);

            if (el != null &&
                el.IV != null &&
                el.IV.Length > 0)
            {
                Securebox._DecryptFile(outputFile, newFileFullPathName, el);
            }
            Securebox.DeleteCurrentFile(outputFile);
        }
Пример #5
0
        private void Decrypt_Button_Click(object sender, RoutedEventArgs e)
        {
            //FileExplorer.WPF.UserControls.Explorer exp = explorer as FileExplorer.WPF.UserControls.Explorer;
            var _fileList = explorer.ViewModel.FileList.Selection.SelectedItems;

            foreach (var el in _fileList)
            {
                //Debug.WriteLine(el.EntryModel.FullPath);
                Securebox.DecryptPreprocess(el.EntryModel.FullPath);
                //Helper.DecryptFile(el.EntryModel.FullPath, el.EntryModel.FullPath + ".sbox", g.ToString());
                // Debug.WriteLine(el.ToString());
            }
            IScriptCommand cmd = UIScriptCommands.FileListRefresh(true, UIScriptCommands.MessageBoxOK("Refresh", "File(s) Decrypted"));

            explorer.ViewModel.Commands.ExecuteAsync(cmd);
        }
Пример #6
0
        private bool ValidateForm(String userName, String firstName, String lastName, String email, String password, String password2, bool checkboxAgree)
        {
            ValidationMessage.Text = "";
            //check if empty
            if (userName == "")
            {
                ValidationMessage.Text = "Username required!";
            }
            else if (firstName == "")
            {
                ValidationMessage.Text = "First name required!";
            }
            else if (lastName == "")
            {
                ValidationMessage.Text = "Last name required!";
            }
            else if (email == "")
            {
                ValidationMessage.Text = "Email required!";
            }
            else if (password == "")
            {
                ValidationMessage.Text = "Password required!";
            }
            else if (password2 == "")
            {
                ValidationMessage.Text = "Password confirmation required!";
            }
            //check if passwords match
            if (ValidationMessage.Text.Length <= 0)
            {
                Securebox util = new Securebox();
                if (password != password2)
                {
                    ValidationMessage.Text = "Passwords do not match!";
                }
                else if (!util.IsValidEmail(emailTextBox.Text))
                {
                    ValidationMessage.Text = "Invalid email!";
                }
            }

            return(ValidationMessage.Text.Length == 0);
        }
Пример #7
0
        private static void _EncryptFile(string inputFile, string outputFile, Guid GUID)
        {
            try
            {
                using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())
                {
                    /* This is for demostrating purposes only.
                     * Ideally you will want the IV key to be different from your key and you should always generate a new one for each encryption in other to achieve maximum security*/
                    byte[] IV = GUID.ToByteArray();

                    byte[] key = GUID.ToByteArray();



                    DatabaseManagement.InsertKey(GUID.ToString(), IV, key);

                    using (FileStream fsCrypt = new FileStream(outputFile, FileMode.Create))
                    {
                        using (ICryptoTransform encryptor = aes.CreateEncryptor(key, IV))
                        {
                            using (CryptoStream cs = new CryptoStream(fsCrypt, encryptor, CryptoStreamMode.Write))
                            {
                                using (FileStream fsIn = new FileStream(inputFile, FileMode.Open))
                                {
                                    int data;
                                    while ((data = fsIn.ReadByte()) != -1)
                                    {
                                        cs.WriteByte((byte)data);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
            Securebox.DeleteCurrentFile(inputFile);
        }
Пример #8
0
        private static Boolean _PostProcessEncryptFile(string inputFile, string outputFile, Guid GUID)
        {
            Boolean isCancelEncryptionProcess = false;

            if (File.Exists(outputFile))
            {
                DialogResult dialogResult = System.Windows.Forms.MessageBox.Show("Would you like to overwrite an existing file?\nSelecting 'No' will append the current file name with a - and a numeral for the current file.\nSelecting 'Cancel' will skip all remaining files as well as this file", "Overwrite confirmation", MessageBoxButtons.YesNoCancel);
                if (dialogResult == DialogResult.Yes)
                {
                    Securebox.DeleteCurrentFile(outputFile);
                    Securebox._PostProcessEncryptFileMethod(inputFile, outputFile, GUID);
                }
                isCancelEncryptionProcess = dialogResult == DialogResult.Cancel;
            }
            else
            {
                Securebox._PostProcessEncryptFileMethod(inputFile, outputFile, GUID);
            }
            Securebox.DeleteCurrentFile(inputFile);
            return(isCancelEncryptionProcess);
        }
Пример #9
0
        private static void _CheckIfNeedUpdate()
        {
            String serverAddress = "http://192.168.1.161:8000/";
            //String serverAddress = "https://securebox.io/";
            var client   = new RestClient(serverAddress);
            var request  = new RestRequest("check-update/", Method.POST);
            var uniqueId = Securebox.GetUniqueSystemIdentifier();
            var currentSecureboxVersion = Securebox.GetVersion();

            request.AddParameter("os", "windows");
            request.AddParameter("uuid", uniqueId);
            request.AddParameter("current_version", currentSecureboxVersion);
            string osVersion = Environment.OSVersion.ToString();

            request.AddParameter("os_version", osVersion);
            IRestResponse <MyToken> response = client.Execute <MyToken>(request);

            try
            {
                //var token = response.Content.ToString();
                RestSharp.Deserializers.JsonDeserializer deserial = new RestSharp.Deserializers.JsonDeserializer();
                MyToken token = deserial.Deserialize <MyToken>(response);
                if (token != null)
                {
                    String updateURL = token.Url;
                    if (currentSecureboxVersion != token.Version)
                    {
                        Securebox._getUpdate(serverAddress + updateURL);
                    }
                }
                else
                {
                    throw new HttpException(404, "Are you sure you're in the right place?");
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.Message);
            }
        }
Пример #10
0
 public static void DecryptFile(string inputFile)
 {
     Securebox._DecryptPreprocess(inputFile);
 }
Пример #11
0
 private void Button_Click(object sender, RoutedEventArgs e)
 {
     Securebox.CheckIfNeedUpdate();
 }
Пример #12
0
 private void explorer_Loaded(object sender, RoutedEventArgs e)
 {
     this.WatchSystem(_selectedPath);
     Securebox.CheckIfNeedUpdate();
 }
Пример #13
0
 public LoginWindow()
 {
     InitializeComponent();
     Securebox.CenterWindowOnScreen(this);
     DatabaseManagement.CreateDatabase();
 }
Пример #14
0
        private bool ValidateForm(String userName, String firstName, String lastName, String email, String password, String password2, bool checkboxAgree)
        {
            

            ValidationMessage.Text = "";
            //check if empty
            if (userName == "")
            {
                ValidationMessage.Text = "Username required!";
            }
            else if (firstName == "")
            {
                ValidationMessage.Text = "First name required!";
            }
            else if (lastName == "")
            {
                ValidationMessage.Text = "Last name required!";
            }
            else if (email == "")
            {
                ValidationMessage.Text = "Email required!";
            }
            else if (password == "")
            {
                ValidationMessage.Text = "Password required!";
            }
            else if (password2 == "")
            {
                ValidationMessage.Text = "Password confirmation required!";
            }
            //check if passwords match
            if( ValidationMessage.Text.Length <= 0)
            {
                Securebox util = new Securebox();
                if (password != password2)
                {
                    ValidationMessage.Text = "Passwords do not match!";
                }
                else if (!util.IsValidEmail(emailTextBox.Text))
                {
                    ValidationMessage.Text = "Invalid email!";
                }
            }

            return ValidationMessage.Text.Length == 0;
        }
Пример #15
0
 public static void CheckIfNeedUpdate()
 {
     Securebox._CheckIfNeedUpdate();
 }
Пример #16
0
 public RegistrationWindow()
 {
     InitializeComponent();
     Securebox.CenterWindowOnScreen(this);
 }
Пример #17
0
 public static void EncryptFile(string inputFile, string outputFile, Guid GUID)
 {
     Securebox._EncryptFile(inputFile, outputFile, GUID);
 }