Used to configure Rijndael encryption service.
Inheritance: System.Configuration.ConfigurationSection
コード例 #1
0
 public static bool OneOrMoreExpiredKeysHaveNoKeyIdentifier(RijndaelEncryptionServiceConfig section)
 {
     return section
         .ExpiredKeys
         .Cast<RijndaelExpiredKey>()
         .Any(x => string.IsNullOrEmpty(x.KeyIdentifier));
 }
コード例 #2
0
 public static bool ExpiredKeysHaveWhiteSpace(RijndaelEncryptionServiceConfig section)
 {
     return section
         .ExpiredKeys
         .Cast<RijndaelExpiredKey>()
         .Any(x => string.IsNullOrWhiteSpace(x.Key));
 }
コード例 #3
0
 public static bool EncryptionKeyListedInExpiredKeys(RijndaelEncryptionServiceConfig section)
 {
     return section
         .ExpiredKeys
         .Cast<RijndaelExpiredKey>()
         .Any(x => x.Key == section.Key);
 }
コード例 #4
0
        public static bool ExpiredKeysHaveDuplicateKeys(RijndaelEncryptionServiceConfig section)
        {
            var items = section
                .ExpiredKeys
                .Cast<RijndaelExpiredKey>()
                .ToList();

            return items.Count != items.Select(x => x.Key).Distinct().Count();
        }
コード例 #5
0
        public void Should_be_true_when_encryption_key_in_expirede_keys()
        {
            var section = new RijndaelEncryptionServiceConfig
            {
                Key = "Key",
                ExpiredKeys = new RijndaelExpiredKeyCollection
                {
                    new RijndaelExpiredKey{Key="Key"},
                }
            };

            Assert.IsTrue(RijndaelEncryptionServiceConfigValidations.EncryptionKeyListedInExpiredKeys(section));
        }
コード例 #6
0
 public static bool ConfigurationHasDuplicateKeyIdentifiers(RijndaelEncryptionServiceConfig section)
 {
     // Combine all key identifier values, filter the empty ones, split them 
     return section
         .ExpiredKeys
         .Cast<RijndaelExpiredKey>()
         .Select(x => x.KeyIdentifier)
         .Union(new[] { section.KeyIdentifier })
         .Where(x => !string.IsNullOrEmpty(x))
         .Select(x => x.Split(';'))
         .SelectMany(x => x)
         .GroupBy(x => x)
         .Any(x => x.Count() > 1);
 }
コード例 #7
0
        public void Should_be_true_when_duplicate_key_identifier_in_concat_expired_keys()
        {
            var section = new RijndaelEncryptionServiceConfig
            {
                KeyIdentifier = "2",
                ExpiredKeys =
                {
                    new RijndaelExpiredKey{ Key="A", KeyIdentifier = "1;4" },
                    new RijndaelExpiredKey{ Key="B", KeyIdentifier = "3;4" }
                }
            };

            Assert.IsTrue(RijndaelEncryptionServiceConfigValidations.ConfigurationHasDuplicateKeyIdentifiers(section));
        }
コード例 #8
0
        public void Should_throw_when_expired_keys_has_duplicate_keys()
        {
            var section = new RijndaelEncryptionServiceConfig
            {
                ExpiredKeys =
                {
                    new RijndaelExpiredKey{ Key = "Key" },
                }
            };

            Assert.Throws<ConfigurationErrorsException>(() =>
            {
                section.ExpiredKeys.Add(new RijndaelExpiredKey
                {
                    Key = "Key",
                    KeyIdentifier = "ID"
                });
            }, "The entry 'Key' has already been added.");
        }
コード例 #9
0
        public void Should_be_true_when_key_identifier_not_in_expired_keys()
        {
            var section = new RijndaelEncryptionServiceConfig
            {
                ExpiredKeys =
                {
                    new RijndaelExpiredKey { Key = "Key" }
                }
            };

            Assert.IsTrue(RijndaelEncryptionServiceConfigValidations.OneOrMoreExpiredKeysHaveNoKeyIdentifier(section));
        }
コード例 #10
0
        public void Should_be_true_when_key_has_whitespace()
        {
            var section = new RijndaelEncryptionServiceConfig
            {
                ExpiredKeys =
                {
                    new RijndaelExpiredKey{ Key = " " }
                }
            };

            Assert.IsTrue(RijndaelEncryptionServiceConfigValidations.ExpiredKeysHaveWhiteSpace(section));
        }