Esempio n. 1
0
        static void DecryptFile(string path)
        {
            var pwd = PromptPassword("Password:");

            var crypto = new PasswordEncryptionProvider(pwd);

            using (var writeHandle = File.Open(path, FileMode.Open, FileAccess.Write, FileShare.Read))
                using (var readHandle = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Write))
                {
                    crypto.DecryptFileAsync(readHandle, writeHandle, CancellationToken.None).GetAwaiter().GetResult();
                }
        }
Esempio n. 2
0
        public DecryptionFile(string encryptedPath, string password)
        {
            _cryptProvider = new PasswordEncryptionProvider(password);
            _encryptedPath = encryptedPath;
            var path = Path.Combine(Path.GetTempPath(), Path.GetFileName(encryptedPath) + ".dcrypt");

            //open the encrypted file
            using (var encryptedFile = new FileStream(encryptedPath, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite | FileShare.Delete))
                //create the temporary decryption file
                using (var decryptedFile = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
                {
                    DecryptedPath = path;
                    _cryptProvider.DecryptFileAsync(encryptedFile, decryptedFile, CancellationToken.None).GetAwaiter().GetResult();
                }
            _origWriteTime = File.GetLastWriteTimeUtc(DecryptedPath);
        }