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);
        }
        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));
            }
        }