NET Caching Library Help
Encryption Example
Examples > Encryption Example

Encryption is supported by the File Cache Provider, the Sqlite Cache Provider, and the SQL Server Cache Provider. To use it simply set the IsEncrypted property equal to true and set the EncryptionKey to the desired password/key on the provider.  By default encryption is off.  Internally the AES encryption in the .NET framework is used to encrypt/decrypt the data.

 

Example

            //Create a file cache with encryption on

            string directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "KellermanSoftware", "NetCachingLibrary", "Tests");

            FileCacheProvider fileCacheProvider = new FileCacheProvider(directory);

            fileCacheProvider.IsEncrypted = true;

            fileCacheProvider.EncryptionKey = "SuperSecret";

            SmartConfig config = new SmartConfig(new MemoryCacheProvider(), fileCacheProvider);

 

            //Specify UserName and LicenseKey for Licensed Mode

            //config.UserName = "my user name";

            //config.LicenseKey = "my license key";

 

            //Instantiate the cache

            SmartCache cache = new SmartCache(config);

 

            //Build parameters for the report

            int month = DateTime.Now.Month;

            int year = DateTime.Now.Year;

 

            //Get the cache key based on the report parameters

            string cacheKey = cache.BuildCacheKey("MonthlySalesReport", month, year);

 

            //Get a long running report

            List<ReportDetail> report = ReportLogic.MonthlySalesReport(month, year);

 

            //Save to the cache encrypted

            cache.Set<List<ReportDetail>>(cacheKey, report);