feat: Implement message encryption and decryption support

- Added IMessageEncryptionService and its implementation MessageEncryptionService for handling message encryption.
- Updated ChannelsController and ChatService to encrypt messages before storing and sending.
- Introduced encryption key retrieval endpoint in ServerController.
- Modified EchoHubDbContext to accommodate increased message content and embed JSON lengths for encrypted data.
- Created migrations to support encryption-related database changes.
- Enhanced FirstRunSetup to ensure encryption key is generated if not present.
- Updated appsettings.example.json to include encryption configuration.
- Added comprehensive unit tests for encryption service and compatibility tests between client and server encryption.
This commit is contained in:
HueByte
2026-02-20 17:16:32 +01:00
parent dfa1b21d32
commit 2efe54e417
26 changed files with 1517 additions and 31 deletions
+6 -2
View File
@@ -6,15 +6,19 @@ namespace EchoHub.Server.Irc;
public class IrcBroadcaster : IChatBroadcaster
{
private readonly IrcGatewayService _gateway;
private readonly IMessageEncryptionService _encryption;
public IrcBroadcaster(IrcGatewayService gateway)
public IrcBroadcaster(IrcGatewayService gateway, IMessageEncryptionService encryption)
{
_gateway = gateway;
_encryption = encryption;
}
public async Task SendMessageToChannelAsync(string channelName, MessageDto message)
{
var lines = IrcMessageFormatter.FormatMessage(message);
// Decrypt content for IRC clients (they can't handle app-layer encryption)
var decryptedMessage = message with { Content = _encryption.Decrypt(message.Content) };
var lines = IrcMessageFormatter.FormatMessage(decryptedMessage);
foreach (var conn in _gateway.GetConnectionsInChannel(channelName))
{