I’m planning to encrypt the messages between two users in a chat application. All chats, users and messages are stored within a Mongo collection. Now I’m asking myself what would be the best approach for this? The main problem here is that the chat should be available on several devices, f.e. mobile and desktop. In this case I need to save all keys on the server to encrypt messages if the user logs in on another device. But saving the keys on the server (even encrypted with a master key) seems to be a problem for me. If someone get’s the master key which encrypts all chat keys, he can encrypt all messages (f.e. if he hacks the application server).
Any idea which approach would be the best for this?