Ejemplo n.º 1
0
        public PortableData Create()
        {
            // 1. Decrypt stream
            ExportDataEncryptor decryptor =
                new ExportDataEncryptor(dataStream);

            using (MemoryStream decrypted = new MemoryStream())
            {
                decryptor.Decrypt(decrypted);
                decrypted.Position = 0;
                // 2. Decompress stream
                ExportDataCompressor decompressor =
                    new ExportDataCompressor(decrypted);
                using (MemoryStream decompressed = new MemoryStream())
                {
                    decompressor.Decompress(decompressed);
                    decompressed.Position = 0;

                    // 3. Deserialize stream
                    PsaTracesSerializer deserializer =
                        new PsaTracesSerializer();
                    PortableData result = deserializer.Deserialize(decompressed);
                    return(result);
                }
            }
        }
Ejemplo n.º 2
0
        public void TestEncryptionDecryption()
        {
            FileStream inFile = new FileStream("Encryption/TextFile.txt",
                                               FileMode.Open);
            ExportDataEncryptor encryptor = new ExportDataEncryptor(inFile);

            MemoryStream encrypted = new MemoryStream();

            encryptor.Encrypt(encrypted);

            encrypted.Flush();
            encrypted.Position = 0;

            BinaryReader rdrEncr = new BinaryReader(encrypted);

            byte[] encrBytes = new byte[encrypted.Length];

            for (int i = 0; i < encrypted.Length; i++)
            {
                encrBytes[i] = rdrEncr.ReadByte();
            }
            //Assert.IsFalse( == "secret service");

            encrypted.Position = 0;

            ExportDataEncryptor decryptor = new ExportDataEncryptor(encrypted);
            MemoryStream        decrypted = new MemoryStream();

            decryptor.Decrypt(decrypted);

            decrypted.Position = 0;

            StreamReader rdrDecr = new StreamReader(decrypted);
            string       decrStr = rdrDecr.ReadToEnd();

            Assert.IsTrue(decrStr.Contains("<tag1>vaue1</tag1>"));
        }
Ejemplo n.º 3
0
        public static PortableData Import(string vtsFilePathname)
        {
            if (String.IsNullOrEmpty(vtsFilePathname))
            {
                throw new ArgumentNullException("vtsFilePathname");
            }
            if (!File.Exists(vtsFilePathname))
            {
                throw new ArgumentException(".VTS File does not exist.");
            }
            PortableData result;

            using (FileStream file = new FileStream(vtsFilePathname,
                                                    FileMode.Open,
                                                    FileAccess.Read,
                                                    FileShare.ReadWrite))
            {
                file.Position = 0;
                ExportDataEncryptor decryptor = new ExportDataEncryptor(file);
                using (MemoryStream decryptedFile = new MemoryStream())
                {
                    decryptor.Decrypt(decryptedFile);
                    //decryptedFile.Position = 0;
                    ExportDataCompressor decompressor =
                        new ExportDataCompressor(decryptedFile);
                    using (MemoryStream decompressed = new MemoryStream())
                    {
                        decompressor.Decompress(decompressed);
                        decompressed.Position = 0;
                        PsaTracesSerializer deserializer = new PsaTracesSerializer();
                        result = deserializer.Deserialize(decompressed);
                    }
                }
            }
            return(result);
        }