コード例 #1
0
        public static void TestInvalidArguments()
        {
            AesKey key = new AesKey();
            AesIV  iv  = new AesIV();

            Assert.Throws <ArgumentNullException>(() =>
            {
                if (new AesCrypto(null) == null)
                {
                }
            });

            Assert.Throws <ArgumentNullException>(() =>
            {
                if (new AesCrypto(null, iv, CipherMode.CBC, PaddingMode.None) == null)
                {
                }
            });

            Assert.Throws <ArgumentNullException>(() =>
            {
                if (new AesCrypto(key, null, CipherMode.CBC, PaddingMode.None) == null)
                {
                }
            });

            Assert.DoesNotThrow(() =>
            {
                if (new AesCrypto(key, iv, CipherMode.CBC, PaddingMode.None) == null)
                {
                }
            });
        }
コード例 #2
0
        public static void TestObjectDisposed()
        {
            AesKey key = new AesKey();
            AesIV  iv  = new AesIV();

            AesCrypto crypto = new AesCrypto(key, iv, CipherMode.CBC, PaddingMode.None);

            crypto.Dispose();

            Assert.Throws <ObjectDisposedException>(() =>
            {
                crypto.Decrypt(new byte[16]);
            });

            Assert.Throws <ObjectDisposedException>(() =>
            {
                crypto.Encrypt(new byte[16]);
            });

            Assert.Throws <ObjectDisposedException>(() =>
            {
                crypto.CreateDecryptingTransform();
            });

            Assert.Throws <ObjectDisposedException>(() =>
            {
                crypto.CreateEncryptingTransform();
            });
        }
コード例 #3
0
        public static void TestMethods()
        {
            AesIV zeroIV = AesIV.Zero;

            Assert.That(zeroIV.GetBytes(), Is.EquivalentTo(new byte[16]), "The IV 'zero' should consist of all zeros.");

            AesIV iv = new AesIV(new byte[16] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
            });

            Assert.That(iv.GetBytes(), Is.EquivalentTo(new byte[16] {
                1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
            }), "An IV specified should consist of just those bytes.");

            iv = new AesIV();
            Assert.That(iv.GetBytes(), Is.Not.EquivalentTo(new byte[16]), "A random iv will in practice never be all zeros.");
        }
コード例 #4
0
        public static void TestInvalidArguments()
        {
            AesIV iv = null;

            Assert.Throws <ArgumentNullException>(() =>
            {
                iv = new AesIV(null);
            });

            Assert.Throws <InternalErrorException>(() =>
            {
                iv = new AesIV(new byte[0]);
            });

            Assert.Throws <InternalErrorException>(() =>
            {
                iv = new AesIV(new byte[32]);
            });

            // Use the instance to avoid FxCop errors.
            Object.Equals(iv, null);
        }