/// <summary> /// Initializes a message encryption service based on the supplied /// <paramref name="configuration"/> /// </summary> /// <param name="configuration">The message queue configuration</param> /// <returns>Returns a task whose result is the initialized message encryption service</returns> public async Task <IMessageEncryptionService> InitMessageEncryptionService(EncryptionElement configuration) { var myConfig = configuration ?? new EncryptionElement(); var provider = GetProvider(myConfig.Provider); if (provider == null || !myConfig.Enabled) { await _diagnosticService.EmitAsync( new DiagnosticEventBuilder(this, DiagnosticEventType.ConfigurationDefault) { Detail = "Message encryption disabled" }.Build()); return(null); } var messageEncryptionService = await provider.CreateMessageEncryptionService(myConfig); await _diagnosticService.EmitAsync( new DiagnosticEventBuilder(this, DiagnosticEventType.ComponentInitialization) { Detail = $"Message encryption service {messageEncryptionService?.GetType().FullName} initialized" }.Build()); return(messageEncryptionService); }
/// <inheritdoc /> public Task <IMessageEncryptionService> CreateMessageEncryptionService(EncryptionElement configuration) { IMessageEncryptionService messageEncryptionService = null; var enabled = configuration.Enabled; if (enabled) { var key = (HexEncodedSecurityKey)configuration.Key; if (key == null) { throw new ConfigurationErrorsException("Attribute 'key' is required for AES message encryption service"); } var fallbackKeys = configuration.FallbackKeys.Select(k => (HexEncodedSecurityKey)k.Key).ToList(); var aesOptions = new AesMessageEncryptionOptions(key) { FallbackKeys = fallbackKeys }; messageEncryptionService = new AesMessageEncryptionService(aesOptions); } return(Task.FromResult(messageEncryptionService)); }