So I am building a client/server system that is similar to email idea where clients exchange messages through the server with the following main requirements (note that the clients are pre-registered to the server and they have to authenticate themselves before any message transmission) :
- Each message should be encrypted and no one is able to read it except the sender and receiver.
- The encryption time should not take long
- The message should be stored encrypted on both the client and server sides(message encrypted once created even if client choose to store it and sent it later: Encryption at the application layer).
I proposed three solutions to accomplish that and I am still studying the pros and cons of each solution if you don't mind helping me:
A- Using symmetric key encryption with the server Each client has a shared secret key with the server Sender A encrypts their message with their shared secret key KA > server decrypts the message with KA and re-encrypt it with receiver B shared secret key KB > receiver B decrypts the message with his shared key KB
The challenge in this solution is the server having to decrypt then encrypt the message again. is it secure or not? why?
B- Using hybrid symmetric and asymmetric key encryption with the server
Server stores 2 different types of key for each registered client
- Shared Key between server and client
- Public Key of client
• When Sender A wants to encrypt a message to Reciever B
- A communicate with server and get B public key Bpk using server shared secret Ka-s
- A generates a shared secret for him and B and encrypts the message with it Ka-b(message)
- A encrypts the generated shared secret with B public key and appends it to the encrypted message Ka-b(message), Bpk(Ka-b)
• When B receives an encrypted message
- B gets Ka-b by decrypting it using his private key Bpri(Bpri(Ka-b))
- B decrypts the message using the shared secret Ka-b
The challenge in this solution is the overhead to encrypt the message where the sender have to generate a key every time he wants to send a message.
C- Using symmetric without server involvement:
Each registered client have a shared key with any other registered client. If A wants to send message to B, he can fetch Ka-b stored shared key and encrypt the message with it then upload it to server.
In this solution the server won't be able to read the message thus less security required on the server.
The challenge here is storing all keys on each client application and managing the keys (synchronization between two clients when renewing an expired shared key )
Is there any better solutions to accomplish both requirements with high security?