Пример #1
0
        public void Challenge10_ImplementCbc()
        {
            var          cipherData = Utils.GetResourceBase64("ImplementCbcMode.txt");
            const string key        = "YELLOW SUBMARINE";
            var          keyData    = Encoding.ASCII.GetBytes(key);
            var          iv         = Enumerable.Repeat((byte)0, 16).ToArray();

            var decryptor = new AesCbcCryptoTransform(keyData, iv);

            var cipherStream = new MemoryStream(cipherData);

            using (var cryptoStream = new CryptoStream(cipherStream, decryptor, CryptoStreamMode.Read))
                using (var reader = new StreamReader(cryptoStream))
                {
                    var plainText = reader.ReadToEnd();
                    var expected  = Utils.GetResourceText("Set2PlainText.txt");

                    Assert.AreEqual(expected, plainText);
                }
        }
Пример #2
0
        public void Challenge10_ImplementCbc()
        {
            var cipherData = Utils.GetResourceBase64("ImplementCbcMode.txt");
            const string key = "YELLOW SUBMARINE";
            var keyData = Encoding.ASCII.GetBytes(key);
            var iv = Enumerable.Repeat((byte)0, 16).ToArray();

            var decryptor = new AesCbcCryptoTransform(keyData, iv);

            var cipherStream = new MemoryStream(cipherData);

            using (var cryptoStream = new CryptoStream(cipherStream, decryptor, CryptoStreamMode.Read))
            using (var reader = new StreamReader(cryptoStream))
            {
                var plainText = reader.ReadToEnd();
                var expected = Utils.GetResourceText("Set2PlainText.txt");

                Assert.AreEqual(expected, plainText);
            }
        }