Beispiel #1
0
        public void TestPdfEncryption()
        {
            // This test does not use TestFileEncryption because it contains
            // some timing measurements for large files.

            // Comment this file out to get time measurements for a large file
            // string test_file_path = "../../test_big.pdf"
            string test_file_path = "../../test.pdf";

            IEncryption enc = new TwoFishEncryption(new TestConfiguration());

            Console.WriteLine("Read: {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            byte[] test_file = File.ReadAllBytes(test_file_path);

            Console.WriteLine("Encrypt: {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            byte[] encrypted_file = enc.Encrypt(test_file);
            Console.WriteLine("Decrypt: {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            byte[] decrypted_file = enc.Decrypt(encrypted_file);

            Console.WriteLine("Write: {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            File.WriteAllBytes("encrypted.pdf", encrypted_file);
            Console.WriteLine("Write: {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            File.WriteAllBytes("decrypted.pdf", decrypted_file);

            Console.WriteLine("Compare: {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            Assert.IsFalse(encrypted_file.SequenceEqual(test_file));
            Console.WriteLine("Compare: {0}", DateTime.Now.ToString("HH:mm:ss tt"));
            Assert.IsTrue(decrypted_file.SequenceEqual(test_file));
        }
Beispiel #2
0
        public string encryptFile(IConfiguration conf)
        {
            System.IO.File.Copy(file_path, getEncryptedFilePath(), overwrite:true);

            var enc = new TwoFishEncryption(conf);
            byte[] encrypted_file = enc.Encrypt(File.ReadAllBytes(getEncryptedFilePath()));
            File.WriteAllBytes(getEncryptedFilePath(), encrypted_file);

            return encrypted_file_path;
        }
Beispiel #3
0
        public void TestStringEncryption()
        {
            string test_string = "Some string to encrypt";

            IEncryption enc = new TwoFishEncryption( new TestConfiguration() );

            string encrypted_string = enc.Encrypt(test_string);
            string decrypted_string = enc.Decrypt(encrypted_string);

            Console.WriteLine("test string='{0}', encrypted string='{1}', decrypted string='{2}'",
                test_string, encrypted_string, decrypted_string);

            Assert.AreNotEqual(test_string, encrypted_string);
            Assert.AreNotEqual(decrypted_string, encrypted_string);
            Assert.AreEqual(test_string, decrypted_string);
        }
Beispiel #4
0
        public void DownloadFile(List<string> storage_path, string file_path)
        {
            var enc = new TwoFishEncryption(conf);

            var ne = new NameEncoder.NameEncoder();
            var str = ne.Encode(storage_path[0]);

            string tmp = System.IO.Path.GetTempPath();

            // Download the file first
            dropBoxStorage.DownloadFile("/" + str, tmp);

            // Then decrypt it and save to the right dir
            byte[] decrypted_file = enc.Decrypt(File.ReadAllBytes(tmp+str));
            File.WriteAllBytes(file_path, decrypted_file);

            File.Delete(tmp + str);
        }
Beispiel #5
0
        private void TestFileEncryption( string file_extension )
        {
            string test_file_path = "../../test." + file_extension;

            IEncryption enc = new TwoFishEncryption(new TestConfiguration());

            byte[] test_file = File.ReadAllBytes(test_file_path);

            byte[] encrypted_file = enc.Encrypt(test_file);
            byte[] decrypted_file = enc.Decrypt(encrypted_file);

            File.WriteAllBytes("encrypted."+file_extension, encrypted_file);
            File.WriteAllBytes("decrypted."+file_extension, decrypted_file);

            Assert.IsFalse(encrypted_file.SequenceEqual(test_file));
            int org_len = decrypted_file.Length;
            Array.Resize(ref decrypted_file, test_file.Length);
            Assert.IsTrue(decrypted_file.SequenceEqual(test_file));
            Assert.IsTrue(test_file.Length - org_len < 10);
        }