コード例 #1
0
        private static string GetEncryptedConfiguration <TSettings>(IServiceScope scope, string settingsParamName)
            where TSettings : class, new()
        {
            var config                 = scope.ServiceProvider.GetRequiredService <IConfiguration>();
            var settings               = config.GetSettings <TSettings>(settingsParamName);
            var encryptationKey        = scope.ServiceProvider.GetRequiredService <EncryptionKey>().Key;
            var encryptedConfiguration = EncrypterManager.Encrypt(settings, encryptationKey);

            return(encryptedConfiguration);
        }
コード例 #2
0
        private static TSettings GetDecryptedConfiguration <TSettings>(IServiceScope scope, string settingsParamName)
            where TSettings : class, new()
        {
            var config          = scope.ServiceProvider.GetRequiredService <IConfiguration>();
            var encryptedValue  = config.GetEncryptedValue(settingsParamName);
            var encryptationKey = scope.ServiceProvider.GetRequiredService <EncryptionKey>().Key;
            var settings        = EncrypterManager.Decrypt <TSettings>(encryptedValue, encryptationKey);

            return(settings);
        }
コード例 #3
0
        private static TSettings GetSettings <TSettings>(IConfiguration configuration, string privateKeyParam, string settingsParamName)
            where TSettings : new()
        {
            var encryptedValue = configuration.GetEncryptedValue(settingsParamName);

            if (string.IsNullOrEmpty(encryptedValue))
            {
                return(configuration.GetSettings <TSettings>(settingsParamName));
            }
            else
            {
                return(EncrypterManager.Decrypt <TSettings>(encryptedValue, privateKeyParam));
            }
        }