I’m faced with this dilemma. I’m creating a chat in C# (there are no problems with the chat itself, I wrote it many times), I came across the need to add end-to-end encryption of messages. I can’t figure out how to implement this correctly. I have a separate server that acts purely as a relay and API (for downloading a list of chats and messages from the database for a specific account).
As I understand it, the sender must encrypt the message with the recipient’s public key. What should the sender do? Saving a message locally under the required ID is not an option, because the client needs to be able to see his messages when logging in from another device. And if the message is encrypted with the recipient’s public key, then it is closed to the sender. Or do you need to send essentially a duplicate message, one encrypted under the sender’s public key, and the second under the recipient’s public key?
Can you tell me how to properly organize the exchange of keys for private chats (1 on 1) and group ones, how best to store them and related things, because I haven’t found anything on this topic.
I thought about storing the sender’s message locally under the ID (which was then inserted into the right place locally), but then I thought that it wouldn’t be visible then on the same account, but on a different device… All that remains is to do it only with a symmetric key where clients encrypt and decrypt with the key which they both know, but I would still like to know how to do it through end-to-end encryption