Ejemplo n.º 1
0
        public void TestCreateEncryptStream()
        {
            var plain = Encoding.UTF8.GetBytes("Hello");
            var key   = new byte[32];
            var iv    = service.GenerateRandomBytes(CryptoService.IvSize);

            Array.Fill(key, (byte)0);

            var          src = new MemoryStream(plain);
            MemoryStream dst = new MemoryStream();

            var encryption = service.CreateEncryptionStream(src, key, iv);

            encryption.CopyTo(dst);
            encryption.Close();

            var enc = dst.ToArray();

            src = new MemoryStream(enc);
            dst = new MemoryStream();

            var decryption = service.CreateDecryptionStream(src, key, iv);

            decryption.CopyTo(dst);
            decryption.Close();

            var dec = dst.ToArray();

            Assert.AreEqual(plain, dec);
        }