IConfigurationSource CreateSource(string defaultName)
 {
     DictionaryConfigurationSource sections = new DictionaryConfigurationSource();
     CryptographySettings settings = new CryptographySettings();
     settings.DefaultSymmetricCryptoProviderName = defaultName;
     settings.SymmetricCryptoProviders.Add(new DpapiSymmetricCryptoProviderData(providerName, DataProtectionScope.CurrentUser));
     settings.SymmetricCryptoProviders.Add(new SymmetricAlgorithmProviderData(symmetricAlgorithm, typeof(RijndaelManaged), "ProtectedKey.file", DataProtectionScope.CurrentUser));
     sections.Add(CryptographySettings.SectionName, settings);
     return sections;
 }
        public void SetUp()
        {
            cryptoSettings = new CryptographySettings();
            settings = new CacheManagerSettings();

            SymmetricStorageEncryptionProviderData encrytionProvider = new SymmetricStorageEncryptionProviderData(providerName, symmetricInstance);
            settings.EncryptionProviders.Add(encrytionProvider);

            cryptoSettings.SymmetricCryptoProviders.Add(new DpapiSymmetricCryptoProviderData(symmetricInstance, DataProtectionScope.CurrentUser));

            configurationSource = new DictionaryConfigurationSource();
            configurationSource.Add(CacheManagerSettings.SectionName, settings);
            configurationSource.Add(CryptographySettings.SectionName, cryptoSettings);

		}
        public void CanBuildCustomHashProviderFromGivenConfiguration()
        {
            CustomHashProviderData customData
                = new CustomHashProviderData("custom", typeof(MockCustomHashProvider));
            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CryptographySettings settings = new CryptographySettings();
            settings.HashProviders.Add(customData);
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            configurationSource.Add(CryptographyConfigurationView.SectionName, settings);

            IHashProvider custom
                = EnterpriseLibraryFactory.BuildUp<IHashProvider>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomHashProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomHashProvider)custom).customValue);
        }
        protected override void Arrange()
        {
            updatableConfigurationSource = new ConfigurationSourceUpdatable();
            cryptoSettings = new CryptographySettings();

            hashProvider = new HashAlgorithmProviderData("hash provider", typeof(MD5), true);
            cryptoSettings.HashProviders.Add(hashProvider);
            cryptoSettings.DefaultHashProviderName = hashProvider.Name;

            symmetricAlgorithmProvider = new CustomSymmetricCryptoProviderData("symm provider", typeof(MockCustomSymmetricProvider));
            cryptoSettings.SymmetricCryptoProviders.Add(symmetricAlgorithmProvider);
            cryptoSettings.DefaultSymmetricCryptoProviderName = symmetricAlgorithmProvider.Name;
            updatableConfigurationSource.Add(CryptographySettings.SectionName, cryptoSettings);

            container = new UnityContainer();
            containerConfigurator = new UnityContainerConfigurator(container);
            EnterpriseLibraryContainer.ConfigureContainer(containerConfigurator, updatableConfigurationSource);
        }
        private static CryptographySettings GenerateBlockSettings()
        {
            CryptographySettings settings = new CryptographySettings();

            settings.HashProviders.Add(new CustomHashProviderData("mockHashProvider1", typeof (MockHashProvider).AssemblyQualifiedName));
            settings.HashProviders.Add(new KeyedHashAlgorithmProviderData("hmac1", typeof (HMACSHA1).AssemblyQualifiedName, true, new byte[] {}));
            settings.HashProviders.Add(new HashAlgorithmProviderData("hashAlgorithm1", typeof (SHA1Managed).AssemblyQualifiedName, false));
            settings.HashProviders.Add( new CustomHashProviderData("provider1", typeof (MockHashProvider).AssemblyQualifiedName));
            settings.HashProviders.Add(new CustomHashProviderData("provider2", typeof (MockHashProvider).AssemblyQualifiedName));

            settings.SymmetricCryptoProviders.Add(new CustomSymmetricCryptoProviderData("mockSymmetric1", typeof (MockSymmetricCryptoProvider).AssemblyQualifiedName));
            settings.SymmetricCryptoProviders.Add(new DpapiSymmetricCryptoProviderData("dpapiSymmetric1", new DpapiSettingsData(new byte[] {}, DpapiStorageMode.User)));
            settings.SymmetricCryptoProviders.Add(new SymmetricAlgorithmProviderData("symmetricAlgorithm1", typeof (RijndaelManaged).AssemblyQualifiedName, Encoding.UTF8.GetBytes("TODO")));
            settings.SymmetricCryptoProviders.Add(new CustomSymmetricCryptoProviderData("provider1",typeof(MockSymmetricCryptoProvider).AssemblyQualifiedName));
            settings.SymmetricCryptoProviders.Add(new CustomSymmetricCryptoProviderData("provider2", typeof(MockSymmetricCryptoProvider).AssemblyQualifiedName ));

            return settings;
        }
        public void CanBuildCustomSymmetricProviderFromGivenConfiguration()
        {
            CustomSymmetricCryptoProviderData customData
                = new CustomSymmetricCryptoProviderData("custom", typeof(MockCustomSymmetricProvider));
            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CryptographySettings settings = new CryptographySettings();
            settings.SymmetricCryptoProviders.Add(customData);

            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            configurationSource.Add(CryptographySettings.SectionName, settings);

            ISymmetricCryptoProvider custom =
                EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource)
                    .GetInstance<ISymmetricCryptoProvider>("custom");

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomSymmetricProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomSymmetricProvider)custom).customValue);
        }
        public void CanBuildCustomHashProviderFromSavedConfiguration()
        {
            CustomHashProviderData customData
                = new CustomHashProviderData("custom", typeof(MockCustomHashProvider));
            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CryptographySettings settings = new CryptographySettings();
            settings.HashProviders.Add(customData);

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>(1);
            sections[CryptographyConfigurationView.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            IHashProvider custom
                = EnterpriseLibraryFactory.BuildUp<IHashProvider>("custom", configurationSource);

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomHashProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomHashProvider)custom).customValue);
        }
        public void CanBuildCustomSymmetricProviderFromSavedConfiguration()
        {
            CustomSymmetricCryptoProviderData customData
                = new CustomSymmetricCryptoProviderData("custom", typeof(MockCustomSymmetricProvider));
            customData.SetAttributeValue(MockCustomProviderBase.AttributeKey, "value1");
            CryptographySettings settings = new CryptographySettings();
            settings.SymmetricCryptoProviders.Add(customData);

            IDictionary<string, ConfigurationSection> sections = new Dictionary<string, ConfigurationSection>(1);
            sections[CryptographySettings.SectionName] = settings;
            IConfigurationSource configurationSource
                = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections);

            ISymmetricCryptoProvider custom =
                EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource)
                    .GetInstance<ISymmetricCryptoProvider>("custom");

            Assert.IsNotNull(custom);
            Assert.AreSame(typeof(MockCustomSymmetricProvider), custom.GetType());
            Assert.AreEqual("value1", ((MockCustomSymmetricProvider)custom).customValue);
        }
 IConfigurationSource CreateSource(string defaultName)
 {
     DictionaryConfigurationSource sections = new DictionaryConfigurationSource();
     CryptographySettings settings = new CryptographySettings();
     settings.DefaultHashProviderName = defaultName;
     settings.HashProviders.Add(new KeyedHashAlgorithmProviderData(providerName, typeof(HMACSHA1), false, keyedHashKeyFile, DataProtectionScope.CurrentUser));
     settings.HashProviders.Add(new HashAlgorithmProviderData(hashAlgorithm, typeof(SHA1Managed), false));
     sections.Add(CryptographySettings.SectionName, settings);
     return sections;
 }
 public void Given()
 {
     cryptographySettings = new CryptographySettings();
     cryptographySettings.HashProviders.Add(
         new HashAlgorithmProviderData("name", typeof(RijndaelManaged), true));
 }
 public void Given()
 {
     cryptographySettings = new CryptographySettings();
     cryptographySettings.SymmetricCryptoProviders.Add(
         new SymmetricAlgorithmProviderData(
             "name",
             typeof(RijndaelManaged),
             "protected key",
             DataProtectionScope.LocalMachine));
 }
        public void Given()
        {
            cryptographySettings =
                new CryptographySettings
                    {
                        DefaultSymmetricCryptoProviderName = "name"

                    };
            cryptographySettings.SymmetricCryptoProviders.Add(
                new SymmetricAlgorithmProviderData(
                    "name", typeof(RijndaelManaged), "protected key", DataProtectionScope.CurrentUser));
        }
 public void Given()
 {
     cryptographySettings = new CryptographySettings();
     customSymmetricCryptoProviderData =
         new CustomSymmetricCryptoProviderData("custom", typeof(MockCustomSymmetricProvider));
     customSymmetricCryptoProviderData.Attributes["foo"] = "bar";
     cryptographySettings.SymmetricCryptoProviders.Add(customSymmetricCryptoProviderData);
 }
 protected override void Arrange()
 {
     cryptographySettings = new CryptographySettings();
 }
 public void Given()
 {
     cryptographySettings = new CryptographySettings();
     cryptographySettings.HashProviders.Add(
         new KeyedHashAlgorithmProviderData(
             "keyed",
             typeof(RijndaelManaged),
             true,
             "protected key",
             DataProtectionScope.LocalMachine));
 }
 private static CryptographySettings GenerateCryptographySettings()
 {
     CryptographySettings settings = new CryptographySettings();
     settings.SymmetricCryptoProviders.Add(new DpapiSymmetricCryptoProviderData("dpapi1", DataProtectionScope.CurrentUser));
     return settings;
 }
 public void Given()
 {
     cryptographySettings = new CryptographySettings();
     cryptographySettings.SymmetricCryptoProviders.Add(
         new DpapiSymmetricCryptoProviderData("dpapi", DataProtectionScope.LocalMachine));
 }
        public void ManageabilityProviderGeneratesProperAdmContent()
        {
            DictionaryConfigurationSource configurationSource = new DictionaryConfigurationSource();
            CryptographySettings cryptographySettings = new CryptographySettings();
            configurationSource.Add("securityCryptographyConfiguration", cryptographySettings);

            MockAdmContentBuilder contentBuilder = new MockAdmContentBuilder();

            contentBuilder.StartCategory("category");
            contentBuilder.StartPolicy("policy", "policy key");
            provider.AddAdministrativeTemplateDirectives(contentBuilder, configurationObject, configurationSource, "TestApp");
            contentBuilder.EndPolicy();
            contentBuilder.EndCategory();

            MockAdmContent content = contentBuilder.GetMockContent();
            IEnumerator<AdmCategory> categoriesEnumerator = content.Categories.GetEnumerator();
            categoriesEnumerator.MoveNext();
            IEnumerator<AdmPolicy> policiesEnumerator = categoriesEnumerator.Current.Policies.GetEnumerator();
            policiesEnumerator.MoveNext();
            IEnumerator<AdmPart> partsEnumerator = policiesEnumerator.Current.Parts.GetEnumerator();

            Assert.IsTrue(partsEnumerator.MoveNext());
            Assert.AreSame(typeof(AdmDropDownListPart), partsEnumerator.Current.GetType());
            Assert.IsNotNull(partsEnumerator.Current.KeyName);
            Assert.AreEqual(SymmetricStorageEncryptionProviderDataManageabilityProvider.SymmetricInstancePropertyName,
                            partsEnumerator.Current.ValueName);
            Assert.IsFalse(partsEnumerator.MoveNext());
        }