Esempio n. 1
0
        public void BasicEncryptionToDisk()
        {
            const string TestValue = "0001000";
            string       tempFile  = GetTempFilePath();

            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");

            using (ZipFile f = ZipFile.Create(tempFile))
            {
                f.Password = "******";

                StringMemoryDataSource m = new StringMemoryDataSource(TestValue);
                f.BeginUpdate();
                f.Add(m, "a.dat");
                f.CommitUpdate();
            }

            using (ZipFile f = new ZipFile(tempFile))
            {
                f.Password = "******";
                Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
            }

            using (ZipFile g = new ZipFile(tempFile))
            {
                g.Password = "******";
                ZipEntry ze = g[0];

                Assert.IsTrue(ze.IsCrypted, "Entry should be encrypted");
                using (StreamReader r = new StreamReader(g.GetInputStream(0)))
                {
                    string data = r.ReadToEnd();
                    Assert.AreEqual(TestValue, data);
                }
            }

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                store.DeleteFile(tempFile);
            }
        }
        public void BasicEncryptionToDisk()
        {
            const string TestValue = "0001000";
            string tempFile = GetTempFilePath();
            Assert.IsNotNull(tempFile, "No permission to execute this test?");

            tempFile = Path.Combine(tempFile, "SharpZipTest.Zip");

            using (ZipFile f = ZipFile.Create(tempFile))
            {
                f.Password = "******";

                StringMemoryDataSource m = new StringMemoryDataSource(TestValue);
                f.BeginUpdate();
                f.Add(m, "a.dat");
                f.CommitUpdate();
            }

            using (ZipFile f = new ZipFile(tempFile))
            {
                f.Password = "******";
                Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
            }

            using (ZipFile g = new ZipFile(tempFile))
            {
                g.Password = "******";
                ZipEntry ze = g[0];

                Assert.IsTrue(ze.IsCrypted, "Entry should be encrypted");
                using (StreamReader r = new StreamReader(g.GetInputStream(0)))
                {
                    string data = r.ReadToEnd();
                    Assert.AreEqual(TestValue, data);
                }
            }

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                store.DeleteFile(tempFile);
            }
        }