Example #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 (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedZipFile f = IsolatedZipFile.Create(tempFile))
                {
                    f.Password = "******";

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

                using (IsolatedZipFile f = new IsolatedZipFile(tempFile))
                {
                    f.Password = "******";
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
                }

                using (IsolatedZipFile g = new IsolatedZipFile(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);
                    }
                }

                store.DeleteFile(tempFile);
            }
        }
Example #2
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 (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                using (IsolatedZipFile f = IsolatedZipFile.Create(tempFile))
                {
                    f.Password = "******";

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

                using (IsolatedZipFile f = new IsolatedZipFile(tempFile))
                {
                    f.Password = "******";
                    // TODO: Testing is not yet ported - Assert.IsTrue(f.TestArchive(true), "Archive test should pass");
                }

                using (IsolatedZipFile g = new IsolatedZipFile(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);
                    }
                }

                store.DeleteFile(tempFile);
            }
        }