// constructor
 public EncryptedConfigurationProvider(EncryptedConfigurationSource source, string thumbprint, StoreLocation storeLocation = StoreLocation.LocalMachine, StoreName storeName = StoreName.My)
     : base(source)
 {
     this.thumbprint    = thumbprint;
     this.storeName     = storeName;
     this.storeLocation = storeLocation;
 }
コード例 #2
0
        public static IConfigurationBuilder AddEncryptedConfigFile(this IConfigurationBuilder builder, EncryptedConfigurationOptions options)
        {
            // the file provider
            IFileProvider provider = null;

            // grab the config filename as we'll use this in a few spots
            string configFilename = GetEnvironmentVariable(options.ConfigFilenameEnv) != null
                    ? Environment.GetEnvironmentVariable(options.ConfigFilenameEnv)
                    : options.ConfigFilename;

            // use own file provider if full path is given for config filename, else it will be left null and will use the builder's
            // file provider later when the configuration is being built
            if (Path.IsPathRooted(configFilename))
            {
                provider = new PhysicalFileProvider(Path.GetDirectoryName(configFilename));
            }

            // define the configuration source
            EncryptedConfigurationSource source = new EncryptedConfigurationSource
            {
                FileProvider = provider,
                Optional     = GetEnvironmentVariable(options.OptionalEnv) != null
                    ? Boolean.Parse(Environment.GetEnvironmentVariable(options.OptionalEnv))
                    : options.Optional,
                Path           = configFilename,
                ReloadOnChange = GetEnvironmentVariable(options.ReloadOnChangeEnv) != null
                    ? Boolean.Parse(Environment.GetEnvironmentVariable(options.ReloadOnChangeEnv))
                    : options.ReloadOnChange,
                Thumbprint = GetEnvironmentVariable(options.ThumbprintEnv) != null
                    ? Environment.GetEnvironmentVariable(options.ThumbprintEnv)
                    : options.Thumbprint,
                StoreLocation = GetEnvironmentVariable(options.StoreLocationEnv) != null
                    ? (StoreLocation)Enum.Parse(typeof(StoreLocation), Environment.GetEnvironmentVariable(options.StoreLocationEnv))
                    : options.StoreLocation
                ,
                StoreName = GetEnvironmentVariable(options.StoreNameEnv) != null
                    ? (StoreName)Enum.Parse(typeof(StoreName), Environment.GetEnvironmentVariable(options.StoreNameEnv))
                    : options.StoreName
            };

            builder.Add(source);
            return(builder);
        }