Beispiel #1
0
        public void Constructor_FullConstructorWithNullKey_Throws(
            [Values(Algorithm.DES, Algorithm.TripleDES, Algorithm.RC2, Algorithm.Rijndael)] Algorithm mode)
        {
            string salt = SymmetricTestsHelper.DEFAULT_SALT;

            byte[] iv  = SymmetricTestsHelper.GetDefaultIV(mode);
            byte[] key = null;

            Symmetric symmetricHelper = new Symmetric(mode, salt, iv, key);
        }
Beispiel #2
0
        public void Constructor_FullConstructorWithEmptySalt_Throws(
            [Values(Algorithm.DES, Algorithm.TripleDES, Algorithm.RC2, Algorithm.Rijndael)] Algorithm mode,
            [Values(64, 128, 48, 192)] int keySize)
        {
            string salt = String.Empty;

            byte[] iv  = SymmetricTestsHelper.GetDefaultIV(mode);
            byte[] key = SymmetricTestsHelper.CreateKey(keySize);

            Symmetric symmetricHelper = new Symmetric(mode, salt, iv, key);
        }
Beispiel #3
0
        public void Constructor_FullConstructorWithInvalidKeyLength_Throws(
            [Values(Algorithm.DES, Algorithm.TripleDES, Algorithm.RC2, Algorithm.Rijndael)] Algorithm mode,
            [Values(16, 1024)] int keySize)
        {
            string salt = SymmetricTestsHelper.DEFAULT_SALT;

            byte[] iv  = SymmetricTestsHelper.GetDefaultIV(mode);
            byte[] key = SymmetricTestsHelper.CreateKey(keySize);

            Symmetric symmetricHelper = new Symmetric(mode, salt, iv, key);
        }
Beispiel #4
0
        public void PropertyIV_DefaultIV_ChangesKeyAndIV(
            [Values(Algorithm.DES, Algorithm.TripleDES, Algorithm.RC2, Algorithm.Rijndael)] Algorithm mode)
        {
            byte[]    newIV           = SymmetricTestsHelper.GetDefaultIV(mode);
            Symmetric symmetricHelper = new Symmetric(mode);

            byte[] oldIV  = symmetricHelper.IV;
            byte[] oldKey = symmetricHelper.Key;

            symmetricHelper.IV = newIV;

            Assert.AreNotEqual(oldIV, symmetricHelper.IV);
            Assert.AreNotEqual(oldKey, symmetricHelper.Key);
        }
Beispiel #5
0
        public void Decrypt_WithEmptyString_ReturnsEmptyString(
            [Values(Algorithm.DES, Algorithm.TripleDES, Algorithm.RC2, Algorithm.Rijndael)] Algorithm mode)
        {
            string secret = String.Empty;

            Symmetric symmetricHelper = new Symmetric(mode);

            symmetricHelper.Salt = SymmetricTestsHelper.DEFAULT_SALT;
            symmetricHelper.IV   = SymmetricTestsHelper.GetDefaultIV(mode);
            symmetricHelper.Key  = SymmetricTestsHelper.GetDefaultKey(mode);

            string actual = symmetricHelper.Decrypt(secret);

            Assert.IsNullOrEmpty(actual);
        }
Beispiel #6
0
        public void Decrypt_WithDefaultSecretString_ReturnsEmptyString(
            [Values(Algorithm.DES, Algorithm.TripleDES, Algorithm.RC2, Algorithm.Rijndael)] Algorithm mode)
        {
            string secret   = SymmetricTestsHelper.GetDefaultSecretString(mode);
            string expected = SymmetricTestsHelper.DEFAULT_MESSAGE;

            Symmetric symmetricHelper = new Symmetric(mode);

            symmetricHelper.Salt = SymmetricTestsHelper.DEFAULT_SALT;
            symmetricHelper.IV   = SymmetricTestsHelper.GetDefaultIV(mode);
            symmetricHelper.Key  = SymmetricTestsHelper.GetDefaultKey(mode);

            string actual = symmetricHelper.Decrypt(secret);

            Assert.AreEqual(expected, actual);
        }
Beispiel #7
0
        public void EncryptToString_WithMessage_ReturnsSecret(
            [Values(Algorithm.DES, Algorithm.TripleDES, Algorithm.RC2, Algorithm.Rijndael)] Algorithm mode)
        {
            string message  = SymmetricTestsHelper.DEFAULT_MESSAGE;
            string expected = SymmetricTestsHelper.GetDefaultSecretString(mode);

            Symmetric symmetricHelper = new Symmetric(mode);

            symmetricHelper.Salt = SymmetricTestsHelper.DEFAULT_SALT;
            symmetricHelper.IV   = SymmetricTestsHelper.GetDefaultIV(mode);
            symmetricHelper.Key  = SymmetricTestsHelper.GetDefaultKey(mode);

            string actual = symmetricHelper.EncryptToString(message);

            Assert.AreEqual(expected, actual);
        }
Beispiel #8
0
        public void Constructor_FullConstructorWithValidParameters_InitializesWithSaltKeyAndIV(
            [Values(Algorithm.DES, Algorithm.TripleDES, Algorithm.RC2, Algorithm.Rijndael)] Algorithm mode,
            [Values(64, 128, 48, 192)] int keySize)
        {
            string salt = SymmetricTestsHelper.DEFAULT_SALT;

            byte[] iv  = SymmetricTestsHelper.GetDefaultIV(mode);
            byte[] key = SymmetricTestsHelper.CreateKey(keySize);

            Symmetric symmetricHelper = new Symmetric(mode, salt, iv, key);

            Assert.AreEqual(mode, symmetricHelper.Mode);
            Assert.AreEqual(keySize, symmetricHelper.KeySize);
            Assert.AreEqual(salt, symmetricHelper.Salt);
            Assert.AreEqual(key, symmetricHelper.Key);
            Assert.AreEqual(iv, symmetricHelper.IV);
        }