Пример #1
0
        public void PimixCryptoStreamDecryptionReadBasicTest()
        {
            foreach (var item in raw)
            {
                ICryptoTransform transform = aesAlgorithm.CreateDecryptor();

                using (var stream = new PimixCryptoStream(File.OpenRead(item.Item1), transform, item.Item3, true))
                {
                    var info = FileInformation.GetInformation(stream, FileProperties.SHA256 | FileProperties.Size | FileProperties.SliceMD5);
                    Assert.AreEqual(item.Item3, info.Size);
                    Assert.AreEqual(item.Item2, info.SHA256);

                    foreach (var b in new List<int> { 8, 11, 12, 16, 33, 100 })
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        var output = new MemoryStream();
                        stream.CopyTo(output, b);

                        info = FileInformation.GetInformation(output, FileProperties.SHA256 | FileProperties.Size | FileProperties.SliceMD5);
                        Assert.AreEqual(item.Item3, info.Size);
                        Assert.AreEqual(item.Item2, info.SHA256);
                    }

                }
            }
        }
Пример #2
0
        public void PimixCryptoStreamDecryptionReadIncompleteEndTest()
        {
            foreach (var item in raw)
            {
                ICryptoTransform transform = aesAlgorithm.CreateDecryptor();

                using (var stream = new PimixCryptoStream(File.OpenRead(item.Item1), transform, item.Item3, true))
                {
                    var baseStream = new MemoryStream();
                    stream.CopyTo(baseStream);

                    foreach (var b in new List<int> { 8, 11, 12, 16, 33, 100 })
                    {
                        stream.Seek(0, SeekOrigin.Begin);
                        stream.Seek(-b, SeekOrigin.End);
                        baseStream.Seek(-b, SeekOrigin.End);
                        for (int i = 0; i < b; i++)
                        {
                            Assert.AreEqual(baseStream.ReadByte(), stream.ReadByte());
                        }
                    }
                }
            }
        }