Example #1
0
        private async void ButtonAccept_Click(object sender, RoutedEventArgs e)
        {
            if (!Validate())
            {
                return;
            }
            if (!File.Exists(_document.Path) || !CanReadFile.Check(_document.Path))
            {
                return;
            }
            _document.Password = textBoxInputBox.Text.Trim();
            if (_isEncrypted)
            {
                App.Store.Dispatch(new EncryptAction
                {
                    createDocumentParams = new List <DocumentModel>
                    {
                        _document
                    }
                });
            }
            else
            {
                App.Store.Dispatch(new DecryptAction
                {
                    createDocumentParams = new List <DocumentModel>
                    {
                        _document
                    }
                });
            }
            await this.ShowMessageAsync("Success", $"{(_isEncrypted ? "Encrypt" : "Decrypt")} Successfully");

            this.Close();
        }
Example #2
0
        public static List <DocumentModel> EncryptDocumentReducer(List <DocumentModel> previousState, EncryptAction action)
        {
            var isUserLoggedIn   = App.Store.GetState().UserProfile != null;
            var documentService  = new DocumentService(App.Store.GetState().DocumentConnectionString);
            var userService      = new UserService(App.Store.GetState().UserConnectionString);
            var newListDocuments = previousState;

            foreach (var document in action.createDocumentParams)
            {
                if (!File.Exists(document.Path) || !CanReadFile.Check(document.Path))
                {
                    continue;
                }
                var rc4 = new RC4(document.Password.Trim(), File.ReadAllBytes(document.Path));
                var encryptedFileRaw  = rc4.Encrypt();
                var newDocumentName   = string.Join("_", Path.GetFileNameWithoutExtension(document.Path), string.Format("{0:yyyy-MM-dd_hh-mm-ss-fff}", DateTime.Now));
                var encryptedFilePath = Path.Combine(App.Store.GetState().DocumentFolder, newDocumentName);
                File.WriteAllBytes(encryptedFilePath, encryptedFileRaw);
                var documentId       = document.Id == Guid.Empty ? Guid.NewGuid() : document.Id;
                var encyptedDocument = new DocumentModel
                {
                    Id          = documentId,
                    Path        = encryptedFilePath,
                    IsEncrypted = true,
                    Name        = Path.GetFileName(newDocumentName),
                    Password    = document.Password.Trim(),
                    FileExt     = Path.GetExtension(document.Path)
                };
                if (isUserLoggedIn)
                {
                    documentService.CreateOrUpdate(encyptedDocument);
                    userService.UpdateUserDocument(App.Store.GetState().UserProfile.Id, documentId);
                }
                else
                {
                    newListDocuments.Add(encyptedDocument);
                }
            }
            return(newListDocuments);
        }
Example #3
0
 private void BtnEncrypt_Click(object sender, System.Windows.RoutedEventArgs e)
 {
     try
     {
         if (!Validate())
         {
             return;
         }
         ChangeControlsStatus(true);
         foreach (var path in _listEncryptFilePath)
         {
             if (!File.Exists(path) || !CanReadFile.Check(path))
             {
                 continue;
             }
             App.Store.Dispatch(new EncryptAction
             {
                 createDocumentParams = new List <DocumentModel>
                 {
                     new DocumentModel
                     {
                         Path     = path,
                         Password = tbPassword.Text.Trim()
                     }
                 }
             });
         }
         BindDocumentDataGrid();
         Process.Start(App.Store.GetState().DocumentFolder);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
     }
     finally
     {
         ChangeControlsStatus(false);
     }
 }