public void CreateDefaultProvider() { SymmetricCryptoProviderFactory factory = new SymmetricCryptoProviderFactory(CreateSource(providerName)); ISymmetricCryptoProvider provider = factory.CreateDefault(); Assert.AreEqual(typeof(DpapiSymmetricCryptoProvider), provider.GetType()); }
public void CanResolveCryptoProvider() { IServiceLocator container = EnterpriseLibraryContainer.CreateDefaultContainer(configurationSource); ISymmetricCryptoProvider provider = container.GetInstance <ISymmetricCryptoProvider>(symmetricInstance); Assert.IsNotNull(provider); Assert.AreSame(typeof(DpapiSymmetricCryptoProvider), provider.GetType()); }
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(CryptographyConfigurationView.SectionName, settings); ISymmetricCryptoProvider custom = EnterpriseLibraryFactory.BuildUp <ISymmetricCryptoProvider>("custom", configurationSource); Assert.IsNotNull(custom); Assert.AreSame(typeof(MockCustomSymmetricProvider), custom.GetType()); Assert.AreEqual("value1", ((MockCustomSymmetricProvider)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[CryptographyConfigurationView.SectionName] = settings; IConfigurationSource configurationSource = ConfigurationTestHelper.SaveSectionsInFileAndReturnConfigurationSource(sections); ISymmetricCryptoProvider custom = EnterpriseLibraryFactory.BuildUp <ISymmetricCryptoProvider>("custom", configurationSource); Assert.IsNotNull(custom); Assert.AreSame(typeof(MockCustomSymmetricProvider), custom.GetType()); Assert.AreEqual("value1", ((MockCustomSymmetricProvider)custom).customValue); }