Пример #1
0
        public void EncryptDecryptManyFilesSpeedTest()
        {
            var directoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());

            while (Directory.Exists(directoryPath))
            {
                directoryPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
            }

            var directoryInfo = Directory.CreateDirectory(directoryPath);
            var size          = 2L * 1024 * 1024;
            var index         = 0;

            while (index < 100)
            {
                var filePath = Path.Combine(directoryPath, string.Format("{0}.txt", Guid.NewGuid()));
                CommonMethods.CreateTestFile(filePath, size);
                index++;
            }

            var files = directoryInfo.GetFiles();


            var encryptWatch = Stopwatch.StartNew();

            foreach (var file in files)
            {
                Crypt.EncryptFile(file.FullName);
            }
            encryptWatch.Stop();
            var encryptSpeed = (float)encryptWatch.ElapsedMilliseconds;


            var decryptWatch = Stopwatch.StartNew();

            foreach (var file in files)
            {
                Crypt.DecryptFile(file.FullName);
            }
            decryptWatch.Stop();
            var decryptSpeed = (float)decryptWatch.ElapsedMilliseconds;


            foreach (var file in files)
            {
                File.Delete(file.FullName);
            }

            directoryInfo.Delete();

            Assert.AreEqual(true, encryptSpeed > 0);
            Assert.AreEqual(true, decryptSpeed > 0);
        }
Пример #2
0
        private void Decrypt(CommonFileInfo fileInfo)
        {
            Crypt.DecryptFile(fileInfo.Path);

            Assert.AreEqual(fileInfo.Content, File.ReadAllText(fileInfo.Path));

            Assert.AreEqual(fileInfo.Size, new FileInfo(fileInfo.Path).Length);
        }
        public void Decrypt(string domain, string path)
        {
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            var target = GetTarget(domain, path);

            if (File.Exists(target))
            {
                crypt.DecryptFile(target);
            }
            else
            {
                throw new FileNotFoundException("file not found", target);
            }
        }