private void ProcessConfig(EncryptionConfig config) { // TODO: [TESTS] (EncryptionService.ProcessConfig) Add tests if (!config.Enabled) { return; } if (string.IsNullOrWhiteSpace(config.Key)) { throw new MissingConfigurationException(ConfigPath, "Key"); } if (string.IsNullOrWhiteSpace(config.IV)) { throw new MissingConfigurationException(ConfigPath, "IV"); } _keyBytes = _utils.FromBase64String(config.Key); _ivBytes = _utils.FromBase64String(config.IV); // Check if we need to warn about potential bad config values if (config.LoggingEnabled && config.LogDecryptInput) { _logger.Error("Logging of Decryption input values has been enabled, " + "this is only for troubleshooting purposes and should " + "be disabled once completed!"); } }
public EncryptionService( ILoggerAdapter <EncryptionService> logger, IEncryptionUtils utils, IConfiguration configuration) { // TODO: [TESTS] (EncryptionService.EncryptionService) Add tests _logger = logger; _utils = utils; _config = MapConfiguration(configuration); }
// Internal methods private EncryptionConfig MapConfiguration(IConfiguration config) { // TODO: [TESTS] (EncryptionService.MapConfiguration) Add tests var encConfig = new EncryptionConfig(); var configSection = config.GetSection(ConfigPath); if (!configSection.Exists()) { _logger.Warning("EncryptionService disabled (config section '{s}' missing)", ConfigPath); } else { configSection.Bind(encConfig); } ProcessConfig(encConfig); return(encConfig); }