Esempio n. 1
0
 public void Export()
 {
     try
     {
         string fileName = filePathDelegate.Invoke();
         PsaTracesSerializer serializer =
             new PsaTracesSerializer(traces);
         using (MemoryStream serialized = new MemoryStream())
         {
             serializer.Serialize(serialized);
             serialized.Position = 0;
             ExportDataCompressor compressor =
                 new ExportDataCompressor(serialized);
             using (MemoryStream compressed = new MemoryStream())
             {
                 compressor.Compress(compressed);
                 compressed.Position = 0;
                 ExportDataEncryptor encryptor =
                     new ExportDataEncryptor(compressed);
                 using (MemoryStream encrypted = new MemoryStream())
                 {
                     encryptor.Encrypt(encrypted);
                     encrypted.Position = 0;
                     if (!String.IsNullOrEmpty(fileName))
                     {
                         using (FileStream output = new FileStream(fileName,
                                                                   FileMode.CreateNew))
                         {
                             encrypted.CopyTo(output);
                         }
                     }
                 }
             }
         }
         if (finishCallback != null)
         {
             finishCallback.Invoke(true, fileName);
         }
     }
     catch (Exception e)
     {
         if (finishCallback != null)
         {
             finishCallback.Invoke(false, e.Message);
         }
     }
 }
        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>"));
        }