public void AttemptingToReadEncryptedDataWithoutDecryptingThrowsException()
        {
            StorageEncryptionFactory factory = new StorageEncryptionFactory(Context);

            IStorageEncryptionProvider encryptionProvider     = factory.CreateSymmetricProvider(CacheManagerName);
            DataBackingStore           encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = unencryptedBackingStore.Load();
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DataBackingStore"/> class
        /// with the specified configuration information.
        /// </summary>
        /// <param name="configurationView">A <see cref="CachingConfigurationView"></see> object</param>
        /// <exception cref="System.Configuration.ConfigurationException">Reflects any failures to read configuration information</exception>
        /// <remarks>Other exceptions thrown depend on the implementation of the underlying database.</remarks>
        public override void Initialize(ConfigurationView configurationView)
        {
            ArgumentValidation.CheckForNullReference(configurationView, "configurationView");
            ArgumentValidation.CheckExpectedType(configurationView, typeof(CachingConfigurationView));

            CachingConfigurationView cachingConfigurationView = (CachingConfigurationView)configurationView;
            DataCacheStorageData     dataConfiguration        = (DataCacheStorageData)cachingConfigurationView.GetCacheStorageDataForCacheManager(CurrentCacheManager);

            partitionName = dataConfiguration.PartitionName;
            DatabaseProviderFactory dataFactory = new DatabaseProviderFactory(cachingConfigurationView.ConfigurationContext);

            database = dataFactory.CreateDatabase(dataConfiguration.DatabaseInstanceName);
            if (dataConfiguration.StorageEncryption != null)
            {
                StorageEncryptionFactory encryptionFactory = new StorageEncryptionFactory(cachingConfigurationView.ConfigurationContext);
                encryptionProvider = encryptionFactory.CreateSymmetricProvider(CurrentCacheManager);
            }
        }
        public void DecryptedDataCanBeReadBackFromDatabase()
        {
            StorageEncryptionFactory factory = new StorageEncryptionFactory(Context);

            IStorageEncryptionProvider encryptionProvider     = factory.CreateSymmetricProvider(CacheManagerName);
            DataBackingStore           encryptingBackingStore = new DataBackingStore(db, "encryptionTests", encryptionProvider);

            encryptingBackingStore.Add(new CacheItem("key", "value", CacheItemPriority.Normal, new MockRefreshAction(), new AlwaysExpired()));
            Hashtable dataInCache = encryptingBackingStore.Load();

            CacheItem retrievedItem = (CacheItem)dataInCache["key"];

            Assert.AreEqual("key", retrievedItem.Key);
            Assert.AreEqual("value", retrievedItem.Value);
            Assert.AreEqual(CacheItemPriority.Normal, retrievedItem.ScavengingPriority);
            Assert.AreEqual(typeof(MockRefreshAction), retrievedItem.RefreshAction.GetType());
            Assert.AreEqual(typeof(AlwaysExpired), retrievedItem.Expirations[0].GetType());
        }
        private void NullEncryptorTests(string instanceName)
        {
            MockStorageEncryptionProvider.Encrypted = false;
            MockStorageEncryptionProvider.Decrypted = false;
            CacheManagerSettings settings = (CacheManagerSettings)Context.GetConfiguration(CacheManagerSettings.SectionName);

            StorageEncryptionFactory factory = new StorageEncryptionFactory(Context);
            IStorageEncryptionProvider provider = factory.CreateSymmetricProvider(settings.CacheManagers[instanceName].Name);

            Assert.IsNotNull(provider);

            byte[] input = new byte[] {0, 1, 2, 3, 4, 5};
            byte[] encrypted = provider.Encrypt(input);

            Assert.IsTrue(MockStorageEncryptionProvider.Encrypted, "static encrypted");

            Assert.IsTrue(CompareBytes(input, encrypted), "no encryption performed");

            byte[] decrypted = provider.Decrypt(encrypted);
            Assert.IsTrue(MockStorageEncryptionProvider.Decrypted, "static decrypted");

            Assert.IsTrue(CompareBytes(encrypted, decrypted), "no decryption performed");
            Assert.IsTrue(CompareBytes(input, decrypted), "no decryption performed2");
        }
Esempio n. 5
0
        private void NullEncryptorTests(string instanceName)
        {
            MockStorageEncryptionProvider.Encrypted = false;
            MockStorageEncryptionProvider.Decrypted = false;
            CacheManagerSettings settings = (CacheManagerSettings)Context.GetConfiguration(CacheManagerSettings.SectionName);

            StorageEncryptionFactory   factory  = new StorageEncryptionFactory(Context);
            IStorageEncryptionProvider provider = factory.CreateSymmetricProvider(settings.CacheManagers[instanceName].Name);

            Assert.IsNotNull(provider);

            byte[] input     = new byte[] { 0, 1, 2, 3, 4, 5 };
            byte[] encrypted = provider.Encrypt(input);

            Assert.IsTrue(MockStorageEncryptionProvider.Encrypted, "static encrypted");

            Assert.IsTrue(CompareBytes(input, encrypted), "no encryption performed");

            byte[] decrypted = provider.Decrypt(encrypted);
            Assert.IsTrue(MockStorageEncryptionProvider.Decrypted, "static decrypted");

            Assert.IsTrue(CompareBytes(encrypted, decrypted), "no decryption performed");
            Assert.IsTrue(CompareBytes(input, decrypted), "no decryption performed2");
        }