Ejemplo n.º 1
0
        protected void EncryptDecryptFileTest(IEncryption crypto)
        {
            string tempPath              = Path.GetTempPath();
            string testOrginalFileName   = Path.Combine(tempPath, "Test.txt");
            string encrypttestFileName   = Path.Combine(tempPath, "Test.txt.enc");
            string testDecryptedFileName = Path.Combine(tempPath, "Test1.txt");

            string plainText = GenerateRandomText(2000);
            string key       = GenerateRandomText(5);

            Trace.WriteLine(string.Format("keyUsed={0}", key));
            Trace.WriteLine(string.Format("plainText={0}", plainText));

            File.WriteAllText(testOrginalFileName, plainText);
            crypto.EncryptFile(testOrginalFileName, encrypttestFileName, key);

            crypto.DecryptFile(encrypttestFileName, testDecryptedFileName, key);

            string unEncryptedText = File.ReadAllText(testDecryptedFileName);

            Assert.AreEqual(plainText, unEncryptedText);

            File.Delete(testOrginalFileName);
            File.Delete(encrypttestFileName);
            File.Delete(testDecryptedFileName);
        }