private bool EncryptFileOperation()
        {
            AxCryptFile.EncryptFileWithBackupAndWipe(_eventArgs.OpenFileFullName, _eventArgs.SaveFileFullName, _eventArgs.Key, _progress);

            _eventArgs.Status = FileOperationStatus.Success;
            return(true);
        }
Esempio n. 2
0
        public static void CheckWatchedFolders(this FileSystemState fileSystemState, ProgressContext progress)
        {
            if (fileSystemState == null)
            {
                throw new ArgumentNullException("fileSystemState");
            }
            AesKey encryptionKey = fileSystemState.KnownKeys.DefaultEncryptionKey;

            if (encryptionKey == null)
            {
                return;
            }
            IEnumerable <IRuntimeFileInfo> files = fileSystemState.DecryptedFilesInWatchedFolders();

            progress.NotifyLevelStart();
            try
            {
                progress.AddTotal(files.Count());
                foreach (IRuntimeFileInfo fileInfo in files)
                {
                    IRuntimeFileInfo destinationFileInfo = fileInfo.CreateEncryptedName();
                    AxCryptFile.EncryptFileWithBackupAndWipe(fileInfo, destinationFileInfo, encryptionKey, progress);
                    progress.AddCount(1);
                }
            }
            finally
            {
                progress.NotifyLevelFinished();
            }
        }
Esempio n. 3
0
        public static void EncryptFile(ProgressContext progress, Action <string, ProgressContext> failure)
        {
            CreatePassphraseViewController passphraseController = new CreatePassphraseViewController {
                EncryptedFileName = DateTime.Now.ToString("yyyyMMddHHmmss")
            };

            NSOpenPanel open = new NSOpenPanel {
                AccessoryView            = passphraseController.View,
                AllowsMultipleSelection  = false,
                CanChooseDirectories     = false,
                CanChooseFiles           = true,
                CanSelectHiddenExtension = true,
                CollectionBehavior       = NSWindowCollectionBehavior.Transient,
                ExtensionHidden          = true,
                Message = "Please select the file you would like to encrypt",
                Prompt  = "Encrypt file",
                Title   = "Encrypt",
                TreatsFilePackagesAsDirectories = false,
            };

            open.Begin(result => {
                if (result == 0 || open.Urls.Length == 0)
                {
                    return;
                }
                if (!open.Urls[0].IsFileUrl)
                {
                    return;
                }
                string sourceFilePath = open.Urls[0].Path;
                open.Close();

                IRuntimeFileInfo sourceFile = OS.Current.FileInfo(sourceFilePath);
                Passphrase passphrase       = passphraseController.VerifiedPassphrase;
                if (passphrase == null)
                {
                    return;
                }

                IRuntimeFileInfo targetFile = GetTargetFileName(sourceFilePath, passphraseController.EncryptedFileName);

                ThreadPool.QueueUserWorkItem(delegate {
                    using (new NSAutoreleasePool()) {
                        AxCryptFile.EncryptFileWithBackupAndWipe(sourceFile, targetFile, passphrase.DerivedPassphrase, progress);
                    };
                });
            });
        }
Esempio n. 4
0
        public static void TestEncryptFileWithBackupAndWipeFileName()
        {
            string sourceFilePath      = _davidCopperfieldTxtPath;
            string destinationFilePath = Path.Combine(Path.GetDirectoryName(sourceFilePath), "David Copperfield-txt.axx");

            AesKey          key      = new AesKey();
            ProgressContext progress = new ProgressContext();

            AxCryptFile.EncryptFileWithBackupAndWipe(sourceFilePath, destinationFilePath, key, progress);

            IRuntimeFileInfo sourceFileInfo      = OS.Current.FileInfo(sourceFilePath);
            IRuntimeFileInfo destinationFileInfo = OS.Current.FileInfo(destinationFilePath);

            Assert.That(sourceFileInfo.Exists, Is.False, "The source should be wiped.");
            Assert.That(destinationFileInfo.Exists, Is.True, "The destination should be created and exist now.");
        }
Esempio n. 5
0
        public static void TestEncryptFileWithBackupFileNameAndWipeNullArguments()
        {
            string sourceFilePath      = _davidCopperfieldTxtPath;
            string destinationFilePath = Path.Combine(Path.GetDirectoryName(sourceFilePath), "David Copperfield-txt.axx");

            string nullFileName = null;

            AesKey key     = new AesKey();
            AesKey nullKey = null;

            ProgressContext progress     = new ProgressContext();
            ProgressContext nullProgress = null;

            Assert.Throws <ArgumentNullException>(() => { AxCryptFile.EncryptFileWithBackupAndWipe(nullFileName, destinationFilePath, key, progress); });
            Assert.Throws <ArgumentNullException>(() => { AxCryptFile.EncryptFileWithBackupAndWipe(sourceFilePath, nullFileName, key, progress); });
            Assert.Throws <ArgumentNullException>(() => { AxCryptFile.EncryptFileWithBackupAndWipe(sourceFilePath, destinationFilePath, nullKey, progress); });
            Assert.Throws <ArgumentNullException>(() => { AxCryptFile.EncryptFileWithBackupAndWipe(sourceFilePath, destinationFilePath, key, nullProgress); });
        }