Esempio n. 1
0
        private static void SaveFile(string filename)
        {
            var fileDetails = new FileInfo(filename);
            var fileObject  = new EFile(fileDetails);
            var temp        = DBController.ReadFileDetails(fileObject.FileLocation).FileName;

            if (fileObject.FileLocation != temp)
            {
                SaveToDBFiles(fileObject);
                var encryptFile = new FileEncryptor(fileObject);
                try
                {
                    encryptFile.FileEncrypt();
                    fileObject.EncryptedHash  = encryptFile.EncryptedHash;
                    fileObject.StoredDateTime = DateTime.Now;
                    DBController.WriteToDB("storedfiles", fileObject);
                    DBController.UpdateDBState(fileObject.FileHash, "true");
                    StatusMessage.PostToRecentsBox(fileObject);
                }
                catch (Exception ex)
                {
                    StatusMessage.PostToActivityBox("Attempting Encryption: " + ex.ToString(), MessageType.ERROR);
                    StatusMessage logger = new StatusMessage();
                    logger.Log("Save button: " + ex);
                }
            }
            else
            {
                MessageBox.Show("Error, file was already saved.", "Error encrypting file", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 2
0
 private static void SaveToDBFiles(EFile fileObject)
 {
     if (!DBController.ContainsPreviousRecord(fileObject.FileLocation))
     {
         DBController.WriteToDB("files", fileObject);
     }
 }
Esempio n. 3
0
        public static EFile ReadEncryptedFileDetails(string encryptedHash)
        {
            var encryptedFile = ReadFromDB("storedfiles", "encryptedhash", encryptedHash);
            var fileDetails   = new EFile()
            {
                FileHash       = encryptedFile[1],
                EncryptedHash  = encryptedFile[2],
                StoredDateTime = DateTime.Parse(encryptedFile[3])
            };

            return(fileDetails);
        }
Esempio n. 4
0
        public static void WriteToDB(string tableName, EFile fileDetails)
        {
            switch (tableName.ToLowerInvariant())
            {
            case "files":
                WriteToTables(tableName, fileDetails.ToStringArray());
                break;

            case "storedfiles":
                WriteToTables(tableName, fileDetails.ToStringArrayEncrypted());
                break;

            default:
                throw new ArgumentException("The table does not exist");
            }
        }
Esempio n. 5
0
        public static EFile ReadFileDetails(string filename)
        {
            var filehash    = new FileHash(filename);
            var normalFile  = ReadFromDB("files", "filename", filename);
            var filedetails = new EFile()
            {
                FileHash     = normalFile[1],
                FileLocation = normalFile[2],
                IsStored     = Convert.ToBoolean(normalFile[3])
            };

            if (!string.IsNullOrEmpty(filedetails.FileLocation))
            {
                var info = new FileInfo(filedetails.FileLocation);
                filedetails.FileName = info.Name;
            }

            return(filedetails);
        }
Esempio n. 6
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (lbStoredFiles.SelectedItems.Count > 0)
            {
                var filename = lbStoredFiles.SelectedItem.ToString();
                if (filename != null && savedFiles != null)
                {
                    EFile fileDetails = LoadData(filename);
                    fileDetails.FileName += ".aes";
                    var decryptFile = new FileEncryptor(fileDetails);
                    if (!decryptFile.IsAlreadyEncrypted())
                    {
                        MessageBox.Show("The file isn't encrypted.", "File Already Encrypted", MessageBoxButton.OK);
                        StatusMessage.PostToActivityBox("Cannot decrypt file: The file was already decrypted", MessageType.ERROR);
                    }

                    try
                    {
                        decryptFile.FileDecrypt();
                        DBController.UpdateDBState(fileDetails.FileHash, "false");
                        DBController.RemoveSavedFile(fileDetails.FileHash);
                        ContainsSavedFiles();
                        MessageBox.Show("File has been successfully retireved!", "File Retrieved", MessageBoxButton.OK, MessageBoxImage.Information);
                        StatusMessage.PostToActivityBox("File retrieved.", MessageType.INFORMATION);
                    }
                    catch (Exception decryptEx)
                    {
                        StatusMessage.PostToActivityBox("Failed to decrypt file!", MessageType.ERROR);
                        var logger = new StatusMessage();
                        logger.Log($"Retrieve File Button: {decryptEx}");
                    }
                }
            }
            else
            {
                MessageBox.Show("Please select a file to retrieve!", "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Esempio n. 7
0
 internal static void PostToRecentsBox(EFile fileObject)
 {
     _mainWindow.tbFileList.Text += $"{fileObject.FileName}:\t{fileObject.FileLocation}\n";
 }