Search code examples
algorithmrsaend-to-endencryption-asymmetric

How can user access any of his messages after RSA encryption?


I am planning to build a site to exchange messages securely using the Rsa algorithm and the end-to-end encryption. Question here: As we know from RSA encryption, if User1 wants to send a message to User2. User 1 requests User2's public key and encrypts the message. User 2 can learn the message’s content by decrypting it using his private key. Well ... how will the first user be able to access his message after it is encrypted? It was stored in the database in an encrypted form. There is an option to solve the problem but I think it is impractical. When User1 creates a message to send to User2, he encrypts it with his public key and keeps it in the database Then he encrypts the original message with User 2's public key and also saves it in the database. Do you have any alternative solutions or suggestions? thnx


Solution

  • The messages between User 1 and User 2 can be encrypted using a symmetric cipher with a key which they both share and only use for messages to each other. The key itself can be stored encrypted with User 1's public key, and separately stored encrypted with User 2's public key, so that each user is able to access the symmetric key to decrypt messages they sent as well as messages they received.