public void CanDeserializeSerializedConfiguration()
        {
            CacheManagerSettings settings = new CacheManagerSettings();

            SymmetricStorageEncryptionProviderData data1 = new SymmetricStorageEncryptionProviderData(name1, symmetric1);
            settings.EncryptionProviders.Add(data1);

            // needed to save configuration
            settings.CacheManagers.Add(new CacheManagerData("foo", 0, 0, 0, "storage"));
            settings.BackingStores.Add(new CustomCacheStorageData("foo", typeof(MockCustomStorageBackingStore)));

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

            CacheManagerSettings roSettigs = (CacheManagerSettings)configurationSource.GetSection(CacheManagerSettings.SectionName);

            Assert.IsNotNull(roSettigs);
            Assert.AreEqual(1, roSettigs.EncryptionProviders.Count);

            Assert.IsNotNull(roSettigs.EncryptionProviders.Get(name1));
            Assert.AreSame(typeof(SymmetricStorageEncryptionProviderData), roSettigs.EncryptionProviders.Get(name1).GetType());
            Assert.AreEqual(name1, roSettigs.EncryptionProviders.Get(name1).Name);
            Assert.AreEqual(symmetric1, ((SymmetricStorageEncryptionProviderData)roSettigs.EncryptionProviders.Get(name1)).SymmetricInstance);
        }
        public void SymmeticStorageEncryptionProviderDataConstructsCorrectly()
        {
            const string symm1 = "symm1";
            const string dpapi1 = "dpapi1";

            SymmetricStorageEncryptionProviderData data = new SymmetricStorageEncryptionProviderData(symm1, dpapi1);

            Assert.AreEqual(symm1, data.Name);
            Assert.AreEqual(dpapi1, data.SymmetricInstance);
            Assert.AreEqual(typeof(SymmetricStorageEncryptionProvider), data.Type);
        }
            public EncryptItemsWithSharedSymmetricProviderBuilder(IBackingStoreEncryptItemsUsing context, string cacheStorageEncryptionProviderName)
                :base(context)

            {
                symmetricCacheStorageEncryption = new SymmetricStorageEncryptionProviderData
                {
                    Name = cacheStorageEncryptionProviderName
                };

                base.AddEncryptionProviderToCachingConfigurationAndBackingStore(symmetricCacheStorageEncryption);
            }
Example #4
0
        /// <summary>
        /// This method supports the Enterprise Library infrastructure and is not intended to be used directly from your code.
        /// Builds an <see cref="SymmetricStorageEncryptionProvider"/> based on an instance of <see cref="StorageEncryptionProviderData"/>.
        /// </summary>
        /// <seealso cref="StorageEncryptionProviderCustomFactory"/>
        /// <param name="context">The <see cref="IBuilderContext"/> that represents the current building process.</param>
        /// <param name="objectConfiguration">The configuration object that describes the object to build. Must be an instance of <see cref="SymmetricStorageEncryptionProviderData"/>.</param>
        /// <param name="configurationSource">The source for configuration objects.</param>
        /// <param name="reflectionCache">The cache to use retrieving reflection information.</param>
        /// <returns>A fully initialized instance of <see cref="SymmetricStorageEncryptionProvider"/>.</returns>
        public IStorageEncryptionProvider Assemble(IBuilderContext context, StorageEncryptionProviderData objectConfiguration, IConfigurationSource configurationSource, ConfigurationReflectionCache reflectionCache)
        {
            SymmetricStorageEncryptionProviderData castedObjectConfiguration
                = (SymmetricStorageEncryptionProviderData)objectConfiguration;

            ISymmetricCryptoProvider symmetricCrytoProvider
                = (ISymmetricCryptoProvider)context.HeadOfChain.BuildUp(context, typeof(ISymmetricCryptoProvider), null, castedObjectConfiguration.SymmetricInstance);

            IStorageEncryptionProvider createdObject
                = new SymmetricStorageEncryptionProvider(symmetricCrytoProvider);

            return(createdObject);
        }
        public void GetProvider()
        {
            SymmetricStorageEncryptionProviderData data = new SymmetricStorageEncryptionProviderData();
            data.Name = "symm1";
            data.SymmetricInstance = "dpapi1";

            SymmetricStorageEncryptionProvider provider = new SymmetricStorageEncryptionProvider();
            provider.ConfigurationName = "InMemoryPersistenceWithSymmetricEncryption";
            provider.Initialize(new CachingConfigurationView(Context));

            byte[] plainText = new byte[] {0, 1, 2, 3, 4};
            byte[] encrypted = provider.Encrypt(plainText);
            Assert.IsFalse(CompareBytes(plainText, encrypted), "enc");

            byte[] decrypted = provider.Decrypt(encrypted);

            Assert.IsTrue(CompareBytes(plainText, decrypted), "dec");
        }